角:为什么不是$ evalAsync称为$ applyAsync? [英] Angular: why isn't $evalAsync called $applyAsync?

查看:567
本文介绍了角:为什么不是$ evalAsync称为$ applyAsync?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关范围角初学者的问题(这里文档)。

Angular beginner question about scopes (docs here).


  1. $ EVAL 执行的范围的上下文中的前pression。

  2. $适用基本要求 $ EVAL 然后 $消化

  3. 为什么 $ evalAsync 通话 $消化太(或者,更precisely,确保 $摘要被调用)?

  1. $eval executes an expression in the context of a scope.
  2. $apply basically calls $eval and then $digest.
  3. Why does $evalAsync call $digest too (or, more precisely, ensure $digest is called)?

这似乎是 $ 评估 异步的确可以称为 $ 适用 异步,不是吗?

It seems to be that $evalAsync should really be called $applyAsync, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆