javascript – 如何在间隔结束后调用函数?

我有一个$interval,调用了一定次数.

间隔运行完毕后,我想让它调用最终的复位功能.我怎样才能做到这一点?

即.

  $scope.clickme = function() {
    var i = 0;

    function lerp() {
      alert(i++);
    }

    function fin(){    //how do I call this function? 
        alert ("all done!")
    }

    $interval(lerp,500,5);
  };

JSFiddle:http://jsfiddle.net/h4cn32e6/1/

最佳答案

The return value of registering an interval function is a promise. This promise will be notified upon each tick of the interval,and will be resolved after count iterations

所以:

$interval(lerp,5).then(fin);

相关文章

kindeditor4.x代码高亮功能默认使用的是prettify插件,prett...
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代...
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小