Skip to content

Order of ngModel & onModelChange #11234

Open
@ObaidUrRehman

Description

@ObaidUrRehman

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
Currently the order of (ngModelChange) and [(ngModel)] on an input element matters. In the following case the ngModelChange callback is called before ngModel updates the value of model:

<select (ngModelChange)="onModelChange()" [(ngModel)]="hero.name" >
   <option>Dexter</option>
   <option>Voltron</option>
</select>

The following however works fine:

<select  [(ngModel)]="hero.name" (ngModelChange)="onModelChange()">
   <option>Dexter</option>
   <option>Voltron</option>
</select>

Expected/desired behavior

Not sure what the expected behavior should be or if this the intended behavior. But I think the order of attributes in an element should not matter.

Reproduction of the problem
Link to plunker: http://plnkr.co/edit/wrVrHYx3pPdLmCKz17RL?p=preview

Open up the console and select Hero name from the drop-down. Notice how the values are printed in console. Swap the order of ngModel and onModelChange and observe the difference.

  • Angular version: 2.0.0-rc.5
  • Browser: Chrome Version 52.0.2743.116 m
  • Language: TypeScript

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions