Components: mat-autocomplete fires onSelectionChange event twice

Created on 17 Oct 2017  路  3Comments  路  Source: angular/components

Bug, feature request, or proposal:

If I have a selected value and change the value the onSelectionChange will fire two events.
One with isUserInput true and one with false.
image
Both will fire soap request and the last soap request is the previous selected value (isUserInput = false).

What is the expected behavior?

Just one event.

What is the current behavior?

What are the steps to reproduce?

It's hard to make a repro for this since I fill the static content with a soap call.
Here is the code I use to fix it:
console.log(_event); if (_event.isUserInput === true) { this.makeParams(_index, _value); }
HTML:
<mat-form-field class="example-full-width">
<input matInput placeholder={{toolbar.fieldname}} class="form-control, input" [matAutocomplete]="a" (input)="filterStatic($event.target.value, toolbar.fieldID, toolbar.minlookupinputlength, toolbar.datasetref, toolbar.refid, toolbar.refarray)"> // trigger a filter
<mat-autocomplete #a="matAutocomplete">
<mat-option *ngFor="let item of static[toolbar.fieldID]" [value]="item.name" (onSelectionChange)="setParams($event, i, item.id)">
<span>{{ item.name }}</span>
</mat-option>
</mat-autocomplete>
</mat-form-field>

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular version: 4.4.4
Angular material version: 2.0.0-beta.12

Is there anything else we should know?

Most helpful comment

This is expected behavior. A selection change includes selection and deselection of an option. When you select a different option, you are implicitly deselecting the old one.

You'd probably be interested in optionSelected.

All 3 comments

This is expected behavior. A selection change includes selection and deselection of an option. When you select a different option, you are implicitly deselecting the old one.

You'd probably be interested in optionSelected.

Closing as a non-issue. @willshowell's comment is correct.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MurhafSousli picture MurhafSousli  路  3Comments

kara picture kara  路  3Comments

crutchcorn picture crutchcorn  路  3Comments

julianobrasil picture julianobrasil  路  3Comments

Hiblton picture Hiblton  路  3Comments