角:为什么不是$ evalAsync称为$ applyAsync? [英] Angular: why isn't $evalAsync called $applyAsync?
问题描述
有关范围角初学者的问题(这里文档)。
Angular beginner question about scopes (docs here).
-
$ EVAL
执行的范围的上下文中的前pression。 -
$适用
基本要求$ EVAL
然后$消化
。 - 为什么
$ evalAsync
通话$消化
太(或者,更precisely,确保$摘要
被调用)?
$eval
executes an expression in the context of a scope.$apply
basically calls$eval
and then$digest
.- Why does
$evalAsync
call$digest
too (or, more precisely, ensure$digest
is called)?
这似乎是 $
的 评估
的异步
的确可以称为 $
的 适用
的异步
,不是吗?
It seems to be that $
eval
Async
should really be called $
apply
Async
, doesn't it?
我是初学者 - 我缺少什么
I'm a beginner -- what am I missing?
推荐答案
$ evalAsync
和 $ applyAsync
目标不同的情况。
$ evalAsync :推迟除权pression到旁的环路电流消化周期的迭代。一个角消化周期循环了几次,直到没有数据是脏的。如果没有消化周期正在进行中,它会启动一个新的消化周期(电话 $适用
法)和评估前pression(电话在它的eval $
方法)。如果你调用一个函数出角范围,但还是喜欢消化脏数据时摘要周期已在进行中,在这种情况下,你不能调用此方法非常有用 $适用
。
$evalAsync: defers the expression to the next loop iteration of current digest cycle. One Angular digest cycle loops for a few times until no data is dirty. If no digest cycle is in progress, it will start a new digest cycle (call $apply
method) and evaluate the expression (call $eval
method) in it. This method is useful if you call a function out of Angular scope but still like to digest the dirty data when a digest cycle is already in progress, in which case you cannot call $apply
.
$ applyAsync :推迟除权pression为摘要的下一个周期。它总是消化开始了新一轮的前pression评估后(呼叫 $适用
方法)。如果您经常执行一些服务回调(如 $ HTTP
服务)出角范围脏范围数据此方法非常有用。然而,如果它为每个回调开始的摘要,有可能是不好的性能。因此,这种方法通过最优化的共享过程中的几个异步回调中消化周期,这胜过方法 $ evalAsync
。
$applyAsync: defers the expression to the next cycle of digest. It always starts a new cycle of digest to after the expression is evaluated (call $apply
method). This method is useful if you frequently execute some service call back (like $http
service) out Angular scope with dirty scope data. However, if it starts a digest for each callback, there may be bad performance. Therefore, this method optimize the process by share the digest cycles among several async callbacks, which outperforms the method $evalAsync
.
这篇关于角:为什么不是$ evalAsync称为$ applyAsync?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!