question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

click event triggers before ng-model changes the value.

See original GitHub issue

I am doing something like this.

<input [(ng-model)]="item.completed" (click)="completed(i)" type="checkbox">

What i want is the when checkbox is clicked it changes the value of item.completed and then it fires the click event.

But what happening is. click events get fired and then ng-model changes the value of item.completed.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:35 (8 by maintainers)

github_iconTop GitHub Comments

62reactions
awerlangcommented, Jul 17, 2016

click is a DOM event, not related to the higher level ngModel. The proper event for this is ngModelChange. If you want to use DOM events, then forget about ngModel and use $event inside the handler or a #ref.

So, instead of

<input [(ngModel)]="item.completed" (click)="completed(i)" type="checkbox">

it should be

<input [(ngModel)]="item.completed" (ngModelChange)="completed(i)" type="checkbox">
15reactions
Drolcommented, Jun 29, 2016

Another workaround that seems to work fine is to wrap everything in your OnChange method in a setTimeout(() => { dostuff });

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngModelChange triggers before the model is actually changed
You can pass the social object as part of modelChange event. Inside component, using event you can check whether checked ...
Read more >
Difference between (change) and (ngModelChange) in Angular
In this post we're going to cover the difference between (change) and (ngModelChange) events with an inside an Angular component.
Read more >
ngModelChange and change events in Angular with examples
Whenever a change happens in ngModel , Angular will trigger ngModelChange ... ngModelChange event parameter contains the changed value.
Read more >
What is the difference between change and ngModelChange ...
ngModelChange: When the user wants to change the model, by entering text into the input, the event callback fires and sets the new...
Read more >
NgModelChange & Change Event in Angular - TekTutorialsHub
It is the @Output property of the ngModel directive, Hence we need to use it along with it. ngModle raises the NgModelChange event,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found