[AngularJS] $interval
$interval
provides an excellent service for timed operations in your AngularJS apps. It has the advantage over setInterval in "normal" Javascript in that it is aware of Angular's view cycles, as well as being mockable for unit tests. Additionally, it returns a promise and provides a lot of flexibility.
Read More: https://docs.angularjs.org/api/ng/service/$interval
<!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>
/**
* Created by Answer1215 on 11/22/2014.
*/ function AppCtrl($q, $interval) { var vm = this;
vm.cancel = cancel;
vm.rejectIt = false; var timer = $interval(function(){
vm.rejectIt = !vm.rejectIt;
doAsync(vm.rejectIt).then(function(data){
console.log(data.resolveData);
}, function(error){
console.log(error.rejectData);
});
}, 600, 10); // 600 ms, 10 times function doAsync(rejectIt){
return $q(function(resolve, reject){
var doneTime = +new Date();
console.log(doneTime);
if(!rejectIt){
resolve({
resolveData: 'resolve it at '+doneTime
});
}else{
reject({
rejectData: 'reject it at '+doneTime
});
}
});
} 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);
[AngularJS] $interval的更多相关文章
- 一篇入门AngularJS
目录 1.AngularJS 应用 2.AngularJS 指令 3.AngularJS 表达式 4.AngularJS 模型 5.AngularJS 控制器 6.AngularJS 作用域 7.An ...
- Failure to find xxx in xxx was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced @ xxx
问题: 在linux服务器上使用maven编译war时报错: 16:41:35 [FATAL] Non-resolvable parent POM for ***: Failure to find * ...
- [LeetCode] Find Right Interval 找右区间
Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...
- [LeetCode] Insert Interval 插入区间
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- angularjs 中的setTimeout(),setInterval() / $interval 和 $timeout
$interval window.setInterval的Angular包装形式.Fn是每次延迟时间后被执行的函数. 间隔函数的返回值是一个承诺.这个承诺将在每个间隔刻度被通知,并且到达规定迭代次数后 ...
- MySQL interval()函数
INTERVAL(N,N1,N2,N3,..........) INTERVAL()函数进行比较列表(N,N1,N2,N3等等)中的N值.该函数如果N<N1返回0,如果N<N2返回1,如果 ...
- oracle11g interval(numtoyminterval())自动创建表分区
Oracle11g通过间隔分区实现按月创建表分区 在项目数据库设计过程中由于单表的数据量非常庞大,需要对表进行分区处理.由于表中的数据是历史交易,故按月分区,提升查询和管理. 由于之前对于表分区了解不 ...
- maven执行报错resolution will not be reattempted until the update interval of nexus h
maven在执行过程中抛错: 引用 ... was cached in the local repository, resolution will not be reattempted until t ...
- 7_nodejs angularjs
webstrom使用: ctrl+b/点击,代码导航,自动跳转到定义 ctrl+n跳转指定类 ctrl+d复制当前行ctrl+enter另起一行ctrl+y删除当前行 ctrl+alt/shift+b ...
- Leetcode Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
随机推荐
- Docker for Windows 里的Shared Drives 设置不生效
原文地址:传送门 问题描述:Docker中的settings里的Shared Drives 选择对应盘符后,点击Apply后无法生效,没办法选择对应盘符进行分享. 解决办法:win+R ,键入gped ...
- loadrunner测试TCP协议服务器性能
loadrunner测试TCP协议服务器性能 . 性能loadrunner测试c 最近对服务器的性能感兴趣,于是开始研究了一阵子loadrunner如何做采用TCP协议交互的服务器的性能测试,对loa ...
- 谈谈对final的理解
1.final修饰类 类不能被继承,类中的所有方法都是final的 2.final修饰方法 方法不能被覆盖,private修饰的方法隐性的添加了final 3.final修饰方法内参数 方法内的参数不 ...
- Java中 @override 报错
报错问题: 在我们导入别人的项目的时候有可能会出现Java类报错,点击错误时提示让我们remove掉@override.这是JDK版本的问题导致的跟源码无关. 解决方法: 方案1.直接删除掉报错的@o ...
- HDU 4417.Super Mario-可持久化线段树(无修改区间小于等于H的数的个数)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- [Codeforces-div.1 24D] Broken robots
[Codeforces-div.1 24D] Broken robots 试题分析 显然设\(f_{i,j}\)为到\((i,j)\)的期望步数,将转移表达式列出来. 首先自己跟自己的项消掉. 然后规 ...
- Problem D: 程序填充(递归函数):数列2项和
Problem D: 程序填充(递归函数):数列2项和 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2601 Solved: 2117 Descrip ...
- Problem E: 矩阵鞍点
AC代码#include<stdio.h> int main() { ][]; ]; int i,j,t,n; while(scanf("%d",&n)!=EO ...
- [转]MySql中创建序列的方法
CREATE TABLE `my_seq` ( `seq` int(10) NOT NULL default 10000) ENGINE=MyISAM DEFAULT CHARSET=utf8 ...
- #iOS问题记录# UIWebView滑动到底部
最近看Tmall的iOS APP,在Tmall的商品简介页面,当拖动到最底部时,会提示继续向上拖动,“查看图文详情”: 觉得这个设计挺好的.闲来无事,自己UIWebView模仿一下,问题是检查UIWe ...