The onSelectionChange
event replaced the selected
event. Now it's possible to recognize when the item is selected or deselected.
It's needed to pass an $event
parameter to the target method to differentiate between the two cases, otherwise md-autocomplete will invoke the method twice (once with the new selected item and once with the deselected/previous value).
It would be nice though if the documentation would be a bit more clear about these changes.
Below how to get only the "on select" event:
Template
<md-autocomplete #panel="mdAutocomplete" [displayWith]="displayFn">
<md-option (onSelectionChange)="selected($event, country)"
*ngFor="let country of filteredCountries | async" [value]="country">
<div class="selector-elements">
{{ country.name }}
</div>
</md-option>
Controller
selected(event: MdOptionSelectionChange, country: ICountry) {
if (event.source.selected) {
this.propagateChange(country);
}
}