New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select change event occurs before ngModel updates #7971
Comments
I have the same issue. I wanted to use the new value when the select option changed. Here's the workaround I used:
In the template
|
You can use (ngModelChange) instead of (change):
|
|
you can also used change method in ts file |
This code is not working prod mode. Any suggestion? |
@nsivaji61 ... it has to be |
I want to fire onchange event when ever user selects anything because i have a cascading dropdown lists. Please suggest. Thanks |
nsivaji61 : Were you able to resolve the issue ? I have same problem of updating cascading drop downs and (change)="somemethod()" is triggered without any user selection change. |
You can build as ng build command then its work in my project |
sample ngValue use |
With angular 8, I saw that event.value works. Best recomemndation is do console.log of the event object, if nothing is working. Then tune your code. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm trying to get the updated select box value, which in this case is an object, when it changes. I'm trying to use the [ngValue]="object" syntax added in #7842 like so
The $event.target.value is a string equal to "1: Object" (The "1" is the index of the array I assume)
However, if in that same method I print out "selectedObj", it's always the old value. It seems as though the change event fires before the model is updated.
edit - If ngFor redraws the array of option values, the index keeps incrementing, so you can't use it to pull the correct object from the array ("searchResults" in this case)
Steps to reproduce and a minimal demo of the problem
http://plnkr.co/edit/7rIHLBWWVqpcPL1NrpDz?p=preview
What steps should we try in your demo to see the problem?
If you look at the console.log()'s, you'll notice that the "Selected Obj: " is always equal to the old value when you select a new value
Expected/desired behavior
I would like either the model object to be updated before the change event fires, or a way to access the new value from the $event obj passed into the change function.
The text was updated successfully, but these errors were encountered: