Maybe it's easier to skip the original call outside the watcher, but there are two reasons why I want to keep it:
1. I want to do that call as soon as possible so it returns as early as possible. 2. Conceptually, it makes more sense to me; I want to do that call even if there's no user input. Nothing has changed yet, it's the initial state. It does work when I use $watch rather than $watchCollection. Instead of creating an artificial collection just to feed it to this watcher, I put all the properties I need to watch together in a single object (there were two other good reasons to do that anyway), and simply use $watch with objectEquality true. When I do that, the if (oldVal !== newVal) prevents it from being called the first time. So this works. My problem is basically solved, and in a better way than I was originally looking for. But the fact that if (oldVal !== newVal) doesn't work for $watchCollection makes me wonder what the use of $watchCollection really is; it seems to make it less useful. I think the ideal solution would be if $watch and $watchCollection would be enhanced so you can pass a boolean specifying whether it should be triggered on initialization. That would keep the callback cleaner and without the additional if (oldVal !== newVal) check. mcv. On Mon, Dec 16, 2013 at 5:40 PM, Sander Elias <[email protected]> wrote: > Hoi Martijn, > > Ok, you are looking for the other way around! > let me recap your needs, > 1. your doing an ajax call > 2. waiting for user input > 3 based on the user input, your repeating the above ajax call, just with > a bit changed data? > > So now you need your watch collection function to skip the first ajax call > it makes? > It is not hard to make it behave like that, however, isn't it more logical > to just skip the ajax call outside the watch collection? > > Regards > Sander > > -- > 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/groups/opt_out. > -- 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/groups/opt_out.
