Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In general, if you have two watchers, D &amp; C that both watch Z, it's best to be explicit about the dependency between D &amp; C, so you don't end up with these ordering issues. </p> <p>I'm not sure if its possible to guarantee the ordering of $watch and other data binding events. But there are a few things you could do.</p> <ol> <li><p>Consolidate</p> <ul> <li>Move your calculation of validity into your regisChange function, instead of using your custom directive. This will be easy in these simple cases where you're only checking a few values. This will eliminate the race condition between your equal directive's $watch handlers firing, and ng-change calling regisChange.</li> </ul></li> <li><p>Be Consistent</p> <ul> <li>You use $watch to check for equality, but then you rely on an event handler to clear an error. Why not $watch both password values and their $valid values (or just the whole input field) so that you can be sure you run your check whenever something changes.</li> </ul></li> </ol> <p>In my mind, it makes sense that the ng-change fires first. It seems to most closely resemble an event handler which I would assume fires immediately after an event, whereas your $watch can only fire after the next $digest() cycle. That being said, it may never be clean to make ng-change and $watch play like how you want them to in this situation.</p> <p>I'm not quite sure what the code is trying to in redisChange function anyway. If you could make a jsfiddle with all of the relevant bits, I could probably be more useful</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload