Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-change's viewChangeListener firing before validity update #9564

@tdakhla

Description

@tdakhla

Before 1.3.0-rc.4, if I had a required, initially empty radio box, state was off a lot (http://jsfiddle.net/butyz12m/):

  • Given ng-click="change(parentForm)", the change fn sees parentForm.$invalid being true (incorrect) and the model value being undefined (incorrect).
  • Given ng-change="change(parentForm)", the change fn sees parentForm.$invalid being true (incorrect) and the model value being b (correct).

After 1.3.0-rc.4, the behavior is now a lot better, but still off slightly in the ng-change case (http://jsfiddle.net/tq321axv/):

  • Given ng-click="change(parentForm)", the change fn sees parentForm.$invalid being false (correct) and the model value being a (correct).
  • Given ng-change="change(parentForm)", the change fn sees parentForm.$invalid being true (incorrect) and the model value being b (correct).

From what I could debug/track down, ng-change is firing early because it's in the $viewChangeListeners queue, which occurs before $digest. I don't know what the appropriate way of delaying the change is, but I'd assume it should stay consistent with when ng-click and ngEvents fire.

I know this is probably under the category of "undefined behavior", but I just wanted to mention it cause I noticed things improving after 1.3.0-rc.4 yet there's still this minor discrepancy between ng-click and ng-change. IMO, things have improved a lot due to ng-model being increased in priority: 1064443#diff-c244afd8def7f268b16ee91a0341c4b2R2397.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions