[AngularJS] $interval
/** * Created by Answer1215 on 11/22/2014. */ function AppCtrl($q, $interval) { var vm = this; vm.cancel = cancel; var timer = $interval(function(){ console.log("doing taskk"); }, 150, 10); // 150 ms, 10 times function success() { console.log("done"); } function error() { console.log("cancelled or error"); } function notify() { console.log("updating"); } timer.then(success, error, notify); function cancel() { $interval.cancel(timer); } } angular.module(‘app‘,[]) .controller(‘AppCtrl‘, AppCtrl);
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="bower_components/angular/angular.min.js"></script> <script src="app.js"></script> </head> <body ng-app="app" ng-controller="AppCtrl as app"> <button ng-click="app.cancel();">cancel</button> </body> </html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。