Radiobutton onClick is emitted before the form value is changed
I'm submitting a ... (check one with "x")
[X] bug report
[ ] feature request
[ ] support request
Plunkr Case (Bug Reports) Please demonstrate your case at stackblitz by using the issue template below. Issues without a test case have much less possibility to be reviewd in detail and assisted.
https://stackblitz.com/edit/github-hbohrm
Current behavior
When using the radio button with ReactiveForms and the onClick() method, the event is fired before the form value is changed.
Expected behavior
The event should be called after the form value is updated.
Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/github-hbohrm.
View the console log. Click on any value. The default is shown on first click.
What is the motivation / use case for changing the behavior?
Motivation is that I need to be able to have actions performed based off the selected radio button value.
Please tell us about your environment:
- Angular version: 7.0.1
- PrimeNG version: Any
There is [(ngModel)] and you can subscribe to (ngModelChange)="selectionChanged($event)" event. Click always goes before model changes.
That doesn't work when my form is a reactive form. That would work if I was using [(ngModel)].
This should honestly work similarly to how Angular Material does its change() event. Angular Material Radio
I had a reactive form and worked around this issue by subscribing to the form value changed in my controller after setting up the form
this.form.get('radioButton').valueChanges.subscribe(v => { console.log(v); // Call what ever function I want to call on change of value });