<!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: