Why angularjs $ scope. Does $ Digest () update the parent area?

I am so confused using the method $scope.$digest(). As far as I know, when we call $scope.$digest(), it will not update the value of the parent scope, therefore

his processes are all observers of the current volume and his children

but when I call $scope.$digest(), it also updates the parent scope, in this case $rootScope.

In the following example, I have a demo. As $rootScopeI have a variable called value_on_root, so every time I call the event onchangeat the entrance, I call the angular function and within the changing value of the variable file_src, which is on $scope, and I change the value for the variable value_on_root, which is on $rootScope, so when I I call $scope.$digest, his update call calls observers on $rootScope.

See an example here

Click to see an example in CODEPEN

+4
source share
2 answers

In this article :

" $digest $scope. $digest(). , ng-click. AngularJS $ digest, $digest(). $digest , . , . , , - , . ng-click /, (, ng-model, $timeout ..), $digest.

! . Angular $digest(). $scope. $Apply(), $rootScope. $Digest(). digest $rootScope , . "

, .

+2

$scope.$digest :

, $scope. $digest()

, . JS ( / , ).

, DOM - .

codepen , :

$rootScope.value_on_root = "Value updated";

, DOM, :

  • value_on_root HTML :

    <div><strong>{{value_on_root}}</strong></div>
    
  • , value_on_root . " " - , AngularJS. :

    , , , JavaScript , , . ( parentScope, ... ).

, value_on_root (- № 1 ), value_on_root (- № 2 ), $digest , :

value_on_root , , $rootScope DOM.

, . value_on_root , {{value_on_root}} HTML. , value_on_root .

$digest $apply , value_on_root .

0

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


All Articles