For watching an object scope variable, is $scope.$watch
with objectEquality
set to true OR $scope.$watchCollection
better?
For
$watchCollection
is optimized for vector arrays []
where elements can be push
and $watch
is good for associative arrays objects {}
$watchCollection
will not watch for depth changes, is like watch with objectEquality set to false.
If you already know to structure of the depth you can optimize like this:
// ctrl watch ?
$scope.$watch('filters', function(newVal, oldVal) {
if(newVal !== oldVal) {
// call with updated filters
}
});
// ctrl watch ?
$scope.$watch('filters.info', function(newVal, oldVal) {
if(newVal !== oldVal) {
// call with updated filters
}
});