Like the title says, I wonder when the scope variable can not be auto watched? Is that correct that all the scope variable that not specified in template should be manually watched if I want to monitor their value changing?
Thanks
Like the title says, I wonder when the scope variable can not be auto watched? Is that correct that all the scope variable that not specified in template should be manually watched if I want to monitor their value changing?
Thanks
You do not need to $watch
any variables or scope properties unless you would like to be notified when they are changed.
Angular implicitly places a $watch
on expressions referenced in templates, i.e. {{ x + y }}
would place a watch on the result of $scope.x + $scope.y
. When these watchers fire, Angular knows to update the view.
All the binded variables are watched by Angular, you don't need to say that you want to watch them, but not all scope variables are watched by Angular.
Watching a variable means that you are gonna be notified when the value of the variable changes. For example, you could show a pop-up when the total is greater than $10. Then you watch the total variable and you perform the action (showing the pop-up).
You can read this question and learn more about watch and Angular: How do I use $scope.$watch and $scope.$apply in AngularJS?