When using a watch in JavaScript, I am encountering an issue. I need to monitor an object within an array, and if any changes occur within the array object, the watch should trigger. However, I am unsure of the best approach to achieve this.
Can someone assist me in understanding the differences between these two methods and recommend the most suitable option for this scenario?
Scope objects:
$scope.$watch('foo', fn)
$scope.$watch(function() {return $scope.foo}, fn);
$scope.$watchCollection('foo', fn)
$scope.$watchCollection(function() {return $scope.foo}, fn);
Non-scope objects:
$scope.$watch(obj.prop, fn)
$scope.$watch(function() {return obj.prop}, fn)
$scope.$watchCollection(obj.prop, fn)
$scope.$watchCollection(function() {return obj.prop}, fn)