angularjs 中 $interval 返回的承诺的参数是什么?
What are the arguments for the promise returned by $interval in angularjs?
我正在使用 Angularjs 1.4。假设我有一个由 $interval.
返回的承诺
var promise = $interval(function () {
}, 1000);
我想利用这个承诺。
promise.then(???)
但是,我不知道这个返回的承诺有哪些参数可用。我无法在 the documentation.
中找到答案
这个返回的promise的参数是什么?
promise 的 then
方法的参数是:
then(successCallback, errorCallback, notifyCallback)
更多信息,see the documentation(查找:"the promise api")
使用的回调以及它们的调用方式将取决于为您提供 promise 对象的函数。在 $interval
的情况下,回调将按如下方式调用:
successCallback
:间隔函数完成时调用(假设设置为过期)
errorCallback
: 出错时调用
notifyCallback
:在间隔计时器的每个滴答声中调用
例子
var promise = $interval(function ()
{
}, 1000, 10);
promise.then(function (){
//On Success: called after 10 seconds (10 x 1000ms).
}, function (){
//On Error: called when an error occurs.
}, function (){
//On Notify: called every second (1000ms).
});
the docs中说:
This promise will be notified upon each tick of the interval, and will
be resolved after count
iterations, or run indefinitely if count
is
not defined. The value of the notification will be the number of
iterations that have run.
所以你必须为then
方法定义一个notifyCallback参数来处理它;此回调的参数将是迭代次数。
我正在使用 Angularjs 1.4。假设我有一个由 $interval.
返回的承诺var promise = $interval(function () {
}, 1000);
我想利用这个承诺。
promise.then(???)
但是,我不知道这个返回的承诺有哪些参数可用。我无法在 the documentation.
中找到答案这个返回的promise的参数是什么?
promise 的 then
方法的参数是:
then(successCallback, errorCallback, notifyCallback)
更多信息,see the documentation(查找:"the promise api")
使用的回调以及它们的调用方式将取决于为您提供 promise 对象的函数。在 $interval
的情况下,回调将按如下方式调用:
successCallback
:间隔函数完成时调用(假设设置为过期)
errorCallback
: 出错时调用
notifyCallback
:在间隔计时器的每个滴答声中调用
例子
var promise = $interval(function ()
{
}, 1000, 10);
promise.then(function (){
//On Success: called after 10 seconds (10 x 1000ms).
}, function (){
//On Error: called when an error occurs.
}, function (){
//On Notify: called every second (1000ms).
});
the docs中说:
This promise will be notified upon each tick of the interval, and will be resolved after
count
iterations, or run indefinitely ifcount
is not defined. The value of the notification will be the number of iterations that have run.
所以你必须为then
方法定义一个notifyCallback参数来处理它;此回调的参数将是迭代次数。