-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
MdAutocomplete onSelectionChange fired multiple times #7369
Comments
This is expected behavior. The first event, The order of the events could arguably be reversed, but I really doubt it's a big deal since most use cases are likely filtering on one or the other by
(also see #4094 (comment)) |
Thanks for the comment @willshowell, that is correct. Closing since it works as expected. |
Indeed, thanks! |
Hi Guys, So im a bit lost. what is the solution for this ? To detect a change on Ngfor ? eg. how would i get the selected option and pass through the beneficiary.value to a function? how does MatAutocomplete has an optionSelected work? will it do what i need it to as above? |
@RichardBoyder this is how I fixed it: Vadorequest/challenge-awesome-movies-viewer@8e1db4e |
Cool thankyou for that. Awesome |
@RichardBoyder also yes, the <mat-autocomplete (optionSelected)="selectBeneficiary($event.option.value)">
<mat-option *ngFor="let beneficiary of beneficiaryList" [value]="beneficiary.value">
</mat-autocomplete> selectBeneficiary(value) {
const selected = this.beneficiaryList.find(b => b.value === value);
console.log('You selected beneficiary:', selected);
} |
Hi It's seems you want only get the value (string) of Someone have an idea to do that without the "onSelectionChange" event which fire twice ( new / old value ) This is my snippet code :)
thank you PS: With $event.option.viewValue, I can get the value (string) of the option so the login, lastname etc but I don't undestand how to get the object USER ;) Edit: Ok I got it. I have to use the [displayWith] input in |
@willshowell |
@willshowell 's solution worked for us. There is a problem here that the documentation currently references this in the API but nowhere in the Overview page, and not in any of the example provided either. I would have thought the examples would use the API... Very hard to find good information on this. /moan |
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. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
Fire only once with the correct value.
What is the current behavior?
The event
onSelectionChange
fires twice instead of once. The first time with the correct value, the second time with the last used value.Also, the behavior changes if we select the value through the keyboard (arrow keys), in this case it fires twice
onSelectionChange
and onceonKeyupEnter
.Since pressing the enter key automatically fires the
onSelectionChange
event, I removed it. (but this should probably be fixed somehow to behave properly, or not, depends on you)But, even if I disable the
onKeyupEnter
, I keep getting two events fired instead of one and didn't find a fix around that.What are the steps to reproduce?
Try selecting several times a value in the list. Works correctly only the first time.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Is there anything else we should know?
Seems related to #4356
You can reproduce the issue through this repository: https://github.com/Vadorequest/challenge-awesome-movies-viewer/blob/master/src/app/header/header.component.html
A simple clone & npm install should do. App runs on http://localhost:4200/
The text was updated successfully, but these errors were encountered: