$watch, $digest, $apply

Source: Internet
Author: User
<span id="Label3"><p>$watch, $digest, $apply<br><br>$watch represents the listener of the data source, and when the data source changes, the second Parameter's callback function is triggered<br>$digest represents an event that triggers a change in the data source<br>$apply represents a package for $digest, he has one more parameter<br><br>$watch<br>The first parameter is the data source to listen to<br>The second parameter is when the listening data source has changed, triggering a callback function, the callback function contains two parameters, respectively (new value, old Value)<br><br>$digest is used to manually trigger a listener event, usually without a manual trigger, but by $apply to invoke<br><br>$apply just made $digest a package to provide manual triggering, then why do I need to manually trigger it, under normal circumstances, under angular, Modify the data source will automatically trigger, but if not in the context of angular, such as browser Dom events, SetTimeout execution, in this case, angular cannot get to the event, so, by using apply to manually trigger, in the parameters of apply to modify the data source<br><br><br>$observe, He was in the definition of directive, for the third parameter of link attr to do the monitoring<br>attr, which is actually the attribute parameter on the defined element, can be obtained by attr the parameters in the DOM<br>When the value of the parameter changes, the callback function is triggered by $observe, and unlike watch, the Listener's host object is Different.</p><p>$watch, $digest, $apply</p></span>

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.