How does angular binding happen?

Below is my understanding of how binding happens in angularJS. It would be great if the experts could provide feedback / comment.

<div ng-controller="ctrlA">
  {{myvar}}
  {{anothervar}}
</div>

$scope.watch( function (scope) {
    return scope.anothervar;
  } ,  function (oldValue, newValue) {
    // code to manupilate HTML with new value!!
  });

$scope.watch( function (scope) {
    return scope.myVar;
  } ,  function (oldValue, newValue) {
    // code to manipulate HTML with new value!!
  });

As soon as angularJS meets {{myVar}} (and {{anothervar}}, an observer (for each variable) is created internally. This observer is created for the $ scope controller 'ctrlA'.

When functions are called in $ timeout, ng-click, etc., they are built into $ scope.apply (). After your function is executed (which may change some area variables), $ apply will cause a digest on rootScope. This will allow you to synchronize the variables throughout the application with the user interface!

$scope.digest , . , . , ( html, !).

. angularJS- - - ( - ) , ? - :

watch ref (for myvar) -> current value (of myvar)
watch ref (for anothervar) -> current value (of anothervar)
+4
1

, Angular , . , / , Angular.

. angularJS - - ( - ) , ?

$scope (.$$watchers), , :

enter image description here

. . .

  • eq , , fn /.
  • exp - , "squiggles" {{raw_expr_value}}.
  • , fn $. $$ watchDelegate (, , "a " ). $scope.$watch('val', _func_), fn _func_.
  • get . - , , .
  • last - , .

, $$, - . :)


. $watch, :

0

Source: https://habr.com/ru/post/1599229/


All Articles