can anyone tell me what to do if I want to first execute ng-click and after that move to another page? now it's just moving to another page and ignoring ng-click
code:
<div ng-repeat='person in ctrl.people'>
<a href ng-click="$storage.x = $index+1; linkClicked($event, $index)">{{person.first_name}}</a>
</div>
controller:
app.controller("mainCtrl", ['$http', '$scope', '$state', '$localStorage', function($http, $scope, $state, $localStorage) {
$scope.linkClicked = function(e, index){
e.preventDefault();
$localStorage.$default.x = index+1;
// do stuff
$state.go('main');
}
$scope.$storage = $localStorage.$default({
x: 0
});
}]);
答案 0 :(得分:0)
您可以在ng-click调用的逻辑内部执行“移动到另一个页面”逻辑
类似这样的事情
<a ng-click="ctrlName.doThing($index)">doesntmatter</a>
并在您的控制器中有此代码
$scope.doThing = function(index) {
$storage.x = index + 1;
document.getElementById('main').scrollIntoView();
}
答案 1 :(得分:0)
您可以通过将$event
传递到ng-click
函数来阻止默认事件,并在执行所需操作后使用$state.go()
<a ng-click="linkClicked($event, $index)">
$scope.linkClicked = function(e, index){
e.preventDefault();
$scope.$storage.x = index+1;
// do stuff
$state.go('someStateName');
}