简体   繁体   中英

ngModal not working in md-select in angular 2 material

Hello I m developing an angular 2 app using material 2. So what I want to do is get data from ng-model into change function of change event, I get data as undefined. Following is the code.

<md-select (change)="trigger(val)" [(ngModel)]="val">
<md-option *ngFor="let item of data">{{item.name}}</md-option>
</md-select>

Component:

trigger(d){}.//// d is undefined.

but if i do this in <select><option></option></select> . I do get the data. Please point me where I m going wrong.

Try by using this code

<md-select (change)="trigger(newValue.value)" #newValue [(ngModel)]="val">
    <md-option *ngFor="let item of data">{{item.name}}</md-option>
</md-select>

trigger(value){

}

also why are you passing val value via parameter ,you can easily get this value without passing value like this

trigger(){
    console.log(this.val, "ngModal value");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM