2017-09-04 9 views
1

md-selectを使用して値を選択するときは、typescriptの関数を呼び出したいと思います。マテリアルデザインでこの目的に使用されるプロパティは何ですか?mdのonselectedイベント - 角度4の選択

<md-select placeholder="State"> 
     <md-option *ngFor="let state of states" [value]="state.code">{{ state.name }} 
    </md-option> 

答えて

0

(change)出力イベントを使用します。 working demo

<md-select placeholder="State"> 
    <md-option *ngFor="let state of states" [value]="state.code" 
      (onSelectionChange)="anotherMethod($event, state)"> 
    {{ state.name }} 
    </md-option> 
</md-select> 

リンク:

<md-select placeholder="State" (change)="someMethod()"> 
    <md-option *ngFor="let state of states" [value]="state.value"> 
    {{ state.viewValue }} 
    </md-option> 
</md-select> 

もう一つの方法は、<md-option>(onSelectionChange)イベントを使用することです。

+1

本当にクールな溶液です。大変ありがとう@ファイサル。 –

+0

あなたは大歓迎です。喜んで:) – Faisal

0

ドキュメントは、物事のこれらの並べ替えについて非常に開いている:

https://material.angular.io/components/select/api

@Output() 
change 
Event emitted when the selected value has been changed by the user. 

<md-select (change)="wasThatSoHard($event)"></md-select> 
+0

それはうまくいきませんでした! –

関連する問題