我有这样的事情:
angular.module('TaskCtrl', [])
.controller('TaskController',
["Service", "$timeout", function (Service, $timeout) {
this.starter = function () {
Service.doSomething();
Service.doSomethingElse();
};
}])
})
我试图在点击下一步按钮并继续下一个视图之间做出延迟。
$timeout
并强制它在加载页面后不在ng-click
上运行?this.starter()
放入$timeout
函数中?我尝试了一些选项,但我想我对this.<xxx>
依赖项感到厌烦。在服务中放置$ timeout非常简单,因为this.starter()
使用来自三种不同服务的东西。
HTML:
<div class="button-bar">
<a class="button next-finish-button" ng-href="#/nextpage"
ng-click="TaskCtrl.starter()">Next</a>
</div>
答案 0 :(得分:0)
这个怎么样:
this.starter = function () {
$timeout(function () {
Service.doSomething();
Service.doSomethingElse();
}, 100);
};
答案 1 :(得分:0)
angular.module('TaskCtrl', [ServiceModule])
.controller('TaskController',['$scope','Service','$timeout', function($scope,Service, $timeout) {
$scope.starter = function () {
$timeout(function(){
Service.doSomething();
Service.doSomethingElse();
},1000); // 1 second delay
}; // end starter
}]); // end TaskController & module TaskCtrl
<强> HTML:强>
<html ng-app="TaskCtrl">
<!-- head stuff here -->
<body>
<div class="button-bar" ng-controller="TaskController">
<a class="button next-finish-button" ng-href="#/nextpage" ng-click="starter()">Next</a>
</div>
</body>
</html>