AngularJS 1.8: advanced patterns when using $scope.$watch on an array of objects
I'm building a feature where I recently switched to I'm working with an scenario with `$scope.$watch` when trying to track changes in an array of objects in my AngularJS 1.8 application... I have a component that manages a list of items, and I want to perform some actions whenever an item in the array is added or removed. Here's a simplified version of my code: ```javascript angular.module('myApp', []).controller('MyController', function($scope) { $scope.items = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }]; // Attempt to watch the array for changes $scope.$watch('items', function(newVal, oldVal) { if (newVal !== oldVal) { console.log('Array changed:', newVal); } }, true); // Function to add an item $scope.addItem = function() { let newItem = { id: 3, name: 'Item 3' }; $scope.items.push(newItem); }; }); ``` The scenario arises when I call the `addItem()` function. I expect the `$watch` to trigger and log 'Array changed:', but it doesn't seem to be firing at all. Iβve confirmed that the item is indeed being added to the array, but for some reason, the `$watch` is not detecting this change. I've tried using the deep watch by passing `true` as the third argument, but it still doesn't work as expected. Additionally, I checked that there are no other watchers or asynchronous operations interfering with the `$scope.items`. When I inspect the console, I donβt see any errors, but I also donβt see the expected log output. Is there a better way to watch for changes in an array while ensuring that it works with the list of objects? Any help or insights into what might be going wrong would be greatly appreciated! I'm working on a application that needs to handle this. How would you solve this? Thanks, I really appreciate it! I recently upgraded to Javascript 3.11. What are your experiences with this?