是否有角度$ q的方法更新?

时间:2015-11-25 02:27:30

标签: javascript angularjs

我看到我们可以处理角度的承诺通知,但它只是作为第三个回调传递给then函数。是否有myPromise.update()方法?

'use strict';

export default function (mod) {

//@ngInject
function MainController($q, $interval) {

    let time = 0;

    let def = $q.defer();


    var prom = def.promise;


    prom.then(function successHandler() {
        console.log('done');
    }, function errorHandler() {
        console.log('error');
    }, function updateHandler(v) {
        console.log(v, 'updated value'); ///is there a nicer interface for handling notify i.e. an update method?
    });


    prom.catch(function () {
        console.log('error');
    });


    var myInterval = $interval(function () {

        time += 1000;

        if (time >= 10000) {
            def.resolve();

            $interval.cancel(myInterval);

        } else {
            def.notify(time);
        }


    }, 1000);
}

mod.controller('MainController', MainController);
}

0 个答案:

没有答案