The solution when using $watchCollection is to use either underscore,
lodash or lazy js to do the comparison _.isEqual(var1, var2). Do your own
object inspection or use angulat.equals(var1, var2)
On Monday, 16 December 2013 11:47:01 UTC, Martijn Vos wrote:
>
>
> My app starts with doing an Ajax call, and when any from a small
> collection of parameters changes, I need to do the ajax call again, so I
> made some watchers for that. Unfortunately, watchers trigger automatically
> after initialization, which I don't want. My controller does ajax call
> first (because I want it to return as soon as possible), then it sets up a
> bunch of other stuff, and finally it sets up the watchers, which trigger,
> doing the ajax call two more times.
>
> The docs claim that if (oldVal !== newVal) {} around my code should
> prevent this. I don't like the extra boilerplate, but fine. Except it
> doesn't work for $watchCollection. It insists that oldVal !== newVal, but
> they really are identical. Changing !== to != doesn't help either.
>
> So what's causing this? And how do I stop it? And wouldn't it be better if
> I could initialize the watcher with a parameter to specify whether it
> should be run on initialization?
>
>
> mcv.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.