'AngularJS : Why to check whether newValue is the same as oldValue in `$watch` listener?
I saw the pattern below many times:
$scope.$watch('full_name', function(newVal, oldVal, scope) {
if(newVal === oldVal) {
return
} else {
}
}
I don't quite understand the if(newVal==oldVal) branch because it looks useless.. Shouldn't the listener callback function only be called when the watched value is changed? If that is the case, shouldn't newVal always be different from oldVal?
If not, does anyone have examples about what can be done in the newVal==oldVal branch?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
