Angularjs Dirty Check mechanism

Source: Internet
Author: User

A long time did not write something, from today, in the blog Park on their past work, study and life to do some combing, summary and temperature. Today the sun outside the window is not so wayward, the sky Baiyun Point, cicada still loud and quiet, sitting quietly on the balcony, blowing wind, tapping the keyboard. In my case, this is a happy life.

To the point, the angularjs dirty check mechanism made a review and summarized as follows:

Reference article:

http://teropa.info/build-your-own-angular/

Http://www.cnblogs.com/likeFlyingFish/p/6183630.html

http://www.ituring.com.cn/article/39865

1, angular is not a periodic trigger dirty check, not a long connection polling check.

2, generally an event loop in the execution to the task queue, such as UI events, AJAX requests or timeout delay events, such as triggering dirty check.

3, Angular each data bound to the UI, there will be a $watch object.

4. All watch stored in the $watchList, a dirty check is called once $apply () or $digest (), traverse check all watch, the data in the latest values rendered on the interface.

5. $digest now run at least one listener at a time. If the monitoring value changes after the first run, all listeners are marked as dirty, and the listener runs a second time. This will run until all the monitored values are no longer changing and the whole situation is stabilized.

6, about $apply, the big idea is that we can execute some code unrelated to angular, which can also change the scope of things, $apply can ensure that the scope of the listener can detect these changes. When people talk about using $apply to integrate code into the "angular life cycle," they are referring to this thing, and nothing is more important than that.

7, but there is a way to delay code in angular, that is, the $evalasync function on the scope. $evalAsync accept a function that is scheduled to be executed in the current ongoing digest or before the next digest. For example, you can defer execution of some code in a listener's listener function, even if it has been delayed, and will still be executed in the existing digest traversal.

Angularjs Dirty Check mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.