首页 > Web开发 > 详细

[AngularJS] $interval

时间:2014-11-22 07:03:28      阅读:647      评论:0      收藏:0      [点我收藏+]
/**
 * 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>

 

bubuko.com,布布扣

[AngularJS] $interval

原文:http://www.cnblogs.com/Answer1215/p/4114651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!