2

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.

Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Sanjay Salunkhe
  • 2,665
  • 5
  • 28
  • 52

1 Answers1

11

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?

Community
  • 1
  • 1
Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
  • its working. but why it doesn't work with string like "$rootScope.name = 'test' " – Sanjay Salunkhe Dec 02 '13 at 09:11
  • @SanjaySalunkhe Because your `MainCtrl`' scope has inherited the `name` from your `rootScope` , and did it "by value". For more deep understanding i suggest you to read Mark Rajcok' post, it puts everything on its places.. – Ivan Chernykh Dec 02 '13 at 09:16