下面是我使用方法是在范围仍然没有得到来自名为NG单击
<div ng-controller="profileEventsCtrl" >
<div class="row mainNavbar" data-ng-show="hideVanityPlate">
<div id="navigatornavbarview" data-ui-view="navigatornavbarview"></div>
</div>
<div class="Profileindex" ng-init="init()">
<div id="profile" style="padding-bottom:20px">
<div class="col-md-12"> <h1>My Events</h1></div>
<div class="row">
<div class="col-md-2">
<div profile-navigation=""></div>
</div><!--col-md-2-->
<div class="col-md-10">
<accordion close-others="true">
<accordion-group is-open="status.open" ng-repeat="userEvent in userEvents">
<accordion-heading>
{{userEvent.Event.Title}}
<div class="condensed medium pull-right date">{{userEvent.Event.FormatedEventDateStartToEnd}}  </div>
<div class="condensed medium lineblock">
<span class="place ">{{userEvent.Event.Location}}</span> | <span class="place" ng-click="switchEvent(userEvent.Event.Code)" ><span>{{SwitchEventText}}</span></span>
</div>
</accordion-heading>
</accordion-group>
</accordion>
</div>
</div>
</div>
这里的HTML是,我使用
(function (ng, app) {
'use strict';
app.controller('profileEventsCtrl', ['$scope', '$location', '$state', '$rootScope', '$q', '$timeout', 'localization','profileSvcs', profileEventsCtrl]);
function profileEventsCtrl($scope, $location, $state, $rootScope, $q, $timeout, localization, profileSvcs) {
$scope.userEvents = {};
$scope.SwitchEventText = "Switch Events"
$scope.init = function() {
$rootScope.currentScope = $scope;
$scope.hideVanityPlate = true;
$scope.getMyEvents();
};
$scope.getMyEvents = function() {
profileSvcs.getMyEvents().then(function (response) {
$scope.userEvents = response.data;
});
}
$scope.switchEvent = function (eventCode) {
var newLocationHash = "/" + $rootScope.cultureCode + "/navigator/" + eventCode + "/profile";
$location.path(newLocationHash);
}
}
})(angular, app);
控制器
所有其他组件工作正常。数据正在从API加载并被填充。但ng-click
不起作用。我不会遇到任何控制台错误,因此难以调试。
此外还要测试功能switchEvent
是否在范围内。我试过ng-init
而不是ng-click
,并且函数被调用了ng-repeat
中的每一行,因此我认为switchEvent
在范围之内。
是你的重复工作? – Sajeetharan
@Sajeetharan是的,ng-repeat工作正常 – kaysush