ANGULARJS[6]-$apply method in $scrope:

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title></title></Head><Body>    <DivNg-app>        <DivNg-controller= "Firstcontroller">{{Date}}</Div>    </Div>    <Scripttype= "Text/javascript"src= "App/index.js"></Script><Scripttype= "Text/javascript"src=".. /.. /vendor/angular/angularjs.js "></Script></Body></HTML>
varFirstcontroller =function($scope) {//$scope Scope    //Declare a model$scope. Date =NewDate ();
//setinterval (function () { ////Although here changes, but does not trigger dirty check //$scope. Date = new Date (); //},1000)SetInterval (function() {$scope. $apply (function() {$scope. Date=NewDate (); }) },1000)};
    • dirty Check : Copy the original object to a snapshot, at some time, compare the current object and the snapshot value, if not the same indicates a change.
    • Angular through the dirty check to know whether the variable changes.

Angular Dirty Check Policy:

-Does not dirty check all objects, when the object is bound to HTML, this object is added as a check object (Wetcher).

-Does not dirty check all the properties, also when the property is bound, this property will be listed as the Check property.

When the angular program is initialized, the properties of the bound object are added as listener objects (watcher), which means that an object is bound to n properties, adding N Watcher.

    • Manual dirty Check: $apply Enter angular context, and then $digest to trigger the dirty check, recommended to the $apply parameters, otherwise it will check all the listening properties in the $scope.
    • It is not recommended to call the $digest () property directly, but to use $apply ().

ANGULARJS[6]-$apply method in $scrope:

Related Article

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.