does not change the value of $scope when using the function



  • I'll just change the meaning in the scoop through ng-clickng-click='currentTab = 1' or ng-click='currentTab = 2', it's the usual buttons, so... $scope.currentTab It will change its meaning. There's also a 3rd Funkz button that also changes the meaning of currentTab, but it's already using a counteraller function. And when I press Funcz, you get a correct number, you change the evidence on the usual, but the Func button doesn't work anymore. Funks's button function is simple:

    $scope.change = function() {
        $rootScope.currentTab = 1;
      }
    

    In this case, it is inexplicable that it is from the Ruth Scoop that it does not want to change back, because in general there should be no difference. ♪ example: https://plnkr.co/edit/yntkXTRS7YC0EgfSNr9k?p=preview

    It'll work correctly with the $scope, but it's the $rootScope that's interesting. ♪



  • This is due to the legacy of the scopes.

    $rootScope - The top level, its fields/practice/methods are available in all scopes.

    When using the directive ng-controller - it creates its own scope, inherited from $rootScope

    The entire conclusion is in the context of the counteraller scope.

    Why does this work for the first time?

    If there is no field in the facility, this field is looking for a prototype facility. In this case, after a button with a function is pressed, the characteristic is added. $rootScopewhich is the prototype of the current staple, and since the current staple does not have this characteristic, the value is shown in the current diagram $rootScope

    Why doesn't it work after the button is pressed?

    When the other buttons are pressed, the field is added. directly to the current cop.

    And the meaning comes directly from it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2