Suppose there is a function by clicking on which in $ scope something changes, for example:

$scope.update = function(newName) { $scope.name = newName; } <button ng-click=update('blabla')>Test</button> 

How does the angular learn whether there were changes in $ scope and start digest? $ scope is a regular object, it is not a function of the type:

  fn(newName) { $scope.name = newName; $digest(); // обход watcher-ов... как он добавляет эту функцию? точно не знаю как она называется... } 

Or an angular when clicking on ng-click automatically starts a function that bypasses all watchers, even if there was no change in $ scope?

  • after clicking on ng-click, the automatic switch starts the function that bypasses all watchers, even if there was no change in $ scope - Grundy

1 answer 1

if you look at the source definition of the ng-click directive, you can see that either the scope.$evalAsync called in the event handler of the native event scope.$apply

Both of these functions start the digest loop, in which it checks whether something has changed and whether the view should be updated.