Looking to create a custom watcher for a collection within my application, I initially believed that Angular would have all the necessary tools at my disposal.
I had access to $watch
, both shallow and deep, as well as $watchCollection
. A $digest
cycle was in place to monitor changes in variables exposed by $scope
, using a dirty checking mechanism to trigger watchers accordingly...
All seemed well! What more could I ask for?
Wrong!
As it turned out, $watchCollection
only responded to the initial change in the watched variable...and that was about it for the powerful watchers. Why did it have to be this way?
Following a reality check, I came to the realization that I needed a somewhat unpleasant loop to track this collection, or perhaps implement a callback system to handle modifications of the variable whenever they occurred.
Does anyone have insights on how this can be achieved in the most elegant manner?
Important note:
For some reason unknown to me, there appeared to be a pesky bug lurking in my code...
Upon resolving it, both $watchCollection(expr, foo)
and $watch(expr, foo, true)
functioned as intended...
I had been misled by a response on this SO post, where a user had commented:
[...] I don't see anything in your code that makes the subsequent requests (to check for new messages). Where does that happen?
I unfortunately took his comments as confirmation of my assumption...my mistake!
Leaving this question as a memento