RaviMittal RaviMittal - 1 year ago 119
AngularJS Question

Angular 2 not giving current state of checkbox

I have started building an ToDo sample app. I am facing an strange issue.
Below is the HTML code for the ToDo List. In that list i am setting ngModel for checkbox and firing an change event as well.

enter image description here

Code to listen the change. I am only printing the current state to console.

enter image description here

Look at below image you can see the current state of the checkbox is checked but in console i am getting the previous state of the checkbox.

enter image description here

Please tell me what is the correct approach to have that working.

Answer Source

This is a known issue

This is working as intended. When the change event is emitted ngModelChange (the (...) part of [(ngModel)] hasn't updated the bound model yet:

See also

There are different workarounds like using event.target.value instead of the value from the model.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download