[AngularJS] $interval

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

时间: 2024-10-25 21:11:29

[AngularJS] $interval的相关文章

JsSIP.UA.JsSIP 总是返回错误:422 Session Interval Too Small

在JsSIP 中 JsSIP.UA.call 总是 返回错误:422 Session Interval Too Small 关于错详情在这篇文章中解释的比较详尽:http://www.cnblogs.com/yoyotl/p/4980817.html 但是没有JsSIP的解决方法 具体的解决方法如下: JsSIP.js中的搜索 SESSION_EXPIRES: 把这个参数改大,  大于120就行了, (要是还不行,就继续加大吧^.^) SESSION_EXPIRES: 90 加大: SESSIO

LeetCode Insert Interval

原题链接在这里:https://leetcode.com/problems/insert-interval/ AC Java: 1 /** 2 * Definition for an interval. 3 * public class Interval { 4 * int start; 5 * int end; 6 * Interval() { start = 0; end = 0; } 7 * Interval(int s, int e) { start = s; end = e; } 8

AngularJS中$timeout和$interval的用法详解

1. 先将$interval,$timeout,作为参数注入到controller中,例如rds.controller('controllerCtrl', ['app', '$scope','$http','$routeParams','$filter','$location','$interval','$timeout', function (app, $scope,$http,$routeParams,$filter,$location,$interval,$timeout) {2.在需要用

Scope in AngularJS

From the RUNBOOM.COM, it said: Scope(作用域) 是应用在 HTML (视图) 和 JavaScript (控制器)之间的纽带. Scope 是一个对象,有可用的方法和属性. Scope 可应用在视图和控制器上. While, how many scopes can we have? is there any structure in it? I got those question when I come to it. After a tough time r

LeetCode57 Insert Interval

题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1:Given intervals [1,3],[6,9], insert and mer

[LeetCode]题解(python):057-Insert Interval

题目来源 https://leetcode.com/problems/insert-interval/ Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Examp

[LeetCode][Java] Insert Interval

题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Given intervals [1,3],[6,9], insert and me

LeetCode --- 57. Insert Interval

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Given intervals [1,3],[6,9], insert and merge

PLSQL_基础系列4_时间间隔INTERVAL

2014-12-08 BaoXinjian 一.摘要 INTERVAL数据类型用来存储两个时间戳之间的时间间隔. 可以指定years and months,或者days,hours,minuts,seconds之间的间隔. ORACLE支持两种INTEVAL类型,它们分别是YEAR TO MONTH和DAY TO SECOND. 每个类型都包含leading field和trailing field.主参数定义要被计算的date或者time,副参数定义最小增长量 二.语法 1. Oracle语法

Interval(南阳oj522)(树状数组)

Interval 时间限制:2000 ms  |  内存限制:65535 KB 难度:4 描述 There are n(1 <= n <= 100000) intervals [ai, bi] and m(1 <= m <= 100000) queries, -100000 <= ai <= bi <= 100000 are integers. Each query contains an integer xi(-100000 <= x <= 1000