angularjs $rootScope.watch not working

Sanjay Salunkhe picture Sanjay Salunkhe · Dec 2, 2013 · Viewed 7k times · Source

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.

Answer

Ivan Chernykh picture Ivan Chernykh · Dec 2, 2013

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?