Search code examples
javascriptangularjsplunkerrootscope

angularjs $rootScope.watch not working


I am new to angularjs. I am trying to learn $watch property . Here is my plunker.

rootScope.$watch property is executing on page load only and not on text change event. But it works properly with $scope.$watch.


Solution

  • It will work if you turn it to Object , like:

      $rootScope.name = { value:'World'};
    

    And bind it like:

      <input type="text" ng-model="name.value"></input>
    

    Working: http://plnkr.co/edit/n4QnivBiRvFMAM91UmIT?p=preview

    Here you have a great explanation: What are the nuances of scope prototypal / prototypical inheritance in AngularJS?