码迷,mamicode.com
首页 > Web开发 > 详细

AngularJS数据绑定中数据监控的机制说明

时间:2017-07-02 12:24:30      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:dia   watch   tin   replace   绑定   imm   mod   guid   rect   

from : http://docs.angularjs.org/guide/scope

When the browser calls into JavaScript the code executes outside the Angular execution context, which means that Angular is unaware of model modifications. To properly process model modifications the execution has to enter the Angular execution context using the $apply method. Only model modifications which execute inside the $apply method will be properly accounted for by Angular. For example if a directive listens on DOM events, such as ng-click it must evaluate the expression inside the $apply method.

After evaluating the expression, the $apply method performs a $digest. In the $digest phase the scope examines all of the $watch expressions and compares them with the previous value. This dirty checking is done asynchronously. This means that assignment such as $scope.username="angular" will not immediately cause a $watch to be notified, instead the $watch notification is delayed until the $digest phase. This delay is desirable, since it coalesces multiple model updates into one $watch notification as well as it guarantees that during the $watch notification no other $watches are running. If a $watch changes the value of the model, it will force additional $digest cycle.

AngularJS数据绑定中数据监控的机制说明

标签:dia   watch   tin   replace   绑定   imm   mod   guid   rect   

原文地址:http://www.cnblogs.com/dhcn/p/7105535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!