S
Angular recalls the meaning and compares it with the previous meaning. If there is a change in meaning, it will trigger a change event. 1. ObserversAngular supports a simple list of watshers(observ contained in $scope facilities. If you check in your annex any $scope, you'll notice that $$watchers.Each watsher(s) is an object which consists of the following:An expression that checks watsher. It could be the name of the object's attribute or something more complex;Last known meaning of expression. This value can be compared to the current expression. If the values are different, watsher will be a function (see below) and the $scope will be marked as dirty (dirty).The function will be performed if the observed expression has changed.2. Methods of establishing observersThere are different ways to identify observers:You can clearly define watsher as a Uscope attribute:$scope.$watch('person.username', validateUnique);
Where? validateUnique this is a function that will be caused if the field changes. person.username♪You can put your expression in the figure brackets in the template.<p>username: {{person.username}}</p>
You can define a directive like ng-model, ng-repeat:<input ng-model="person.username" />
3. $digestAt the launch of your angular application, the $digest cycle begins.There are two more cycles in the $digest cycle. One of the cycles is processing the $evalAsync line, the other is the $watch list. The value of the $digest is fulfilled until your expression is synchronized. That means that the $evalAsync will be devastated and there will be no change in the $watch.The $digest Cycle is the circumvention of the $scope and all of its subsidiaries of visibility. For each $scope, his $watchers will be retrieved and his expression will be assessed for each element. If the new meaning of the expression differs from that of the last known, the function of observer shall be called for. This function may overlap part DOM, rewrite the value in $scope, cause AJAX request, etc.4. What happens if watsher works.If watsher works, the app knows something's changed and the $scope's supposed to be dirty.The functions of observers may be modified by other variables of current or parent $scope, so the $digest cycle will be called again. This ensures that all $scopes will eventually be synchronized (the value of all traceable expressions will be the same as the previous terrain of the $digest cycle). But this behavior of the $digest cycle could cause cycling, so default may be caused up to 10 times in a row until all the $scopes are marked as clean. If this limit is exceeded, we'll see such a mistake in the console:10 $digest() iterations reached. Aborting!
5. Productivity.As you can see, with any changes in the annex to understand how to react, the angular will check every single watsher in the entire USscope hierarchy.From the point of view of the developer, it's very productive, because you don't have to think about how to track the variations and display them in the template. If the expression changed, Angular would simply replace it.From the point of view of the car, it's not very effective and it's gonna slow your app.From a human perspective:Slowly. - Everything that's happening faster than 50ms is unmarked for a man. So 50ms can be considered as "momental."Limited - You can't actually show more than, like, 2,000 information to a man on one page. If you have more information on the page than that, it's actually a bad UI, and users can't process it anyway.Thus, the real question is: How many comparisons can you make in the 50ms browser? This is a complex issue, as many factors are in the game. Here. http://jsperf.com/angularjs-digest/6 which creates 10,000 observers. In the modern browser, it takes less than 6ms. Internet Explorer 8 - about 40ms. As you can see, it's not a problem, even for old browsers. There is one nuance: Comparisons must be simple to fit into a time limit. Unfortunately, it's too easy to add slow comparisons to your annex, so it's very easy to build a slow app when you don't know exactly what you're doing.6. One-time connectionMore productivity can be achieved through the use of one-time connections. Such expressions will be recorded in your annex ' s template once and will not be monitored in the $digest cycle, respectively, we are receiving productivity gains and we can take a place in the $digest cycle for more important expressions. If you know that some of the elements of your application are being created in your template alone and no longer changing, one-time connection is what you need. Simple example of one-time connection:<h1>{{ ::title }}</h1>
Source: https://stackoverflow.com/questions/9682092/how-does-data-binding-work-in-angularjs