I couldn't figure out how to watch a variable that binded to this variable in angularjs.
Here is what I have tried.
in html,
<input type="text" ng-model="vm.text"/>--{{vm.text}}--
<p>{{vm.count}} times changed</p>
<input type="text" ng-model="text1"/>--{{text1}}--
<p>{{count1}} times changed</p>
in app.js
$scope.$watch('this.text', function() {
console.log('watch 1');
this.count=this.count+1;
});
$scope.$watch('text1', function() {
// do something here
console.log('watch 2');
$scope.count1=$scope.count1+1;
});
and plunker link for the same.
I could watch text1 but I couldn't watch text1.
Can anyone please explain me how to watch text1?
thanks in advance
$scope.$watch('vm.text')