[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 ...
随机推荐
- C#读取RSS源,并利用Solr索引
折磨我几天的问题今天终于解决了,分享一下近期solr使用的一些经验. 本来是用nutch在爬取页面,可是客户需要爬取RSS,而且可以识别那些页面是通过RSS源抓取出来的.nutch虽然自带解析RSS的 ...
- oracle导入DMP步骤
oracle导入DMP步骤如下:1.已经存在的数据库需要进行以下的操作,如果不存在,可略过: 删除用户 drop user SUDMDB cascade; 删除表空间和数据文件 ...
- PHP策略设计模式
<?php /** 抽象策略角色,以接口实现 */ interface Strategy { /** 算法接口 */ public function algorithmInterface(); ...
- sonar rule
bug类型: 1.".equals()" should not be used to test the values of "Atomic" classes. ...
- python笔记二:常用数据类型操作
1.切片:常用于取list或tuple的部分元素的操作 1)l=[1,2,3,4,5,6] l[:3]表示取前3个值,l[1:5]表示1到5个值, L[-3:]从列表最后往前数即最后3个数.... 2 ...
- 【POJ 2154】 Color (置换、burnside引理)
Color Description Beads of N colors are connected together into a circular necklace of N beads (N< ...
- JavaWeb数据库配置
项目结构 在 JDBC 中 DBUtil.java 加载配置文件时,路径使用的是Java项目的相对路径.存在本地的. // 加载配置文件 Properties p = new Properties() ...
- 检测是否为n的因子 Exercise07_06
/** * @author 冰樱梦 * 时间:2018年下半年 * 题目:检测是否为n的因子 * */ public class Exercise07_06 { public static void ...
- DOM操作(一)
DOM中比较常用的类型有Element类型,Text类型,Attr类型,Comment类型(注释),Document类型(文档),DocumentFragment类型. Element类型 提供了对元 ...
- Codeforces Round #344 (Div. 2) C. Report 其他
C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...