Search code examples
angularangular-material2md-autocomplete

material 2 Autocomplete: select option


I want to call a function when an option is selected. After some search it seem that i have to use :

property optionSelections of MdAutocompleteTrigger

In the documentation : https://material.angular.io/components/component/autocomplete optionSelections Stream of autocomplete option selections.

I dont understand that , what is a stream, how to implement this ?


Solution

  • On md-option you can set "onSelect"

    <md-autocomplete #auto="mdAutocomplete">
        <md-option (onSelect)="callSomeFunction()" *ngFor="let state of states" [value]="state.name">{{ state.name }}</md-option>
    </md-autocomplete>
    

    Since beta 3, functionality has changed:

    <md-autocomplete #auto="mdAutocomplete">
        <md-option (onSelectionChange)="callSomeFunction()" *ngFor="let state of states" [value]="state.name">{{ state.name }}</md-option>
    </md-autocomplete>