码迷,mamicode.com
首页 > Web开发 > 详细

[AngularJS] $interval

时间:2014-11-22 07:04:33      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   on   div   

/**
 * 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

标签:style   blog   http   io   ar   color   sp   on   div   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!