如何从mat-select下拉选项更改ngModel绑定值

时间:2018-02-28 05:36:44

标签: angular typescript angular2-template angular-material2

我尝试在mat-select下拉列表中使用ngModel绑定值。我在选项ex中有一些值:A - A / C Loss,B - BURGLARY。 一旦我选中了复选框,我只需要绑定A,B就可以删除A / C Loss和BURGLARY。

这是选项值示例: enter image description here 这是ngModel绑定值示例: enter image description here 需要精确地导致ngModel:A,B,CF,CI,CM,CR

代码示例:

<mat-select placeholder="Select Events" [formControl]="selectEventitems" [(ngModel)]="selectedEventValue" (change)="onEventsChange($event)" (focus)="onEventfocus($event)" multiple>
     <mat-option class="select-all" value="SelectAll">Select All</mat-option>
     <mat-option *ngFor="let event of getAllEvents" [value]="event.eventrpt_id">{{event.eventrpt_id}} - {{event.descr}}</mat-option>
</mat-select>

1 个答案:

答案 0 :(得分:0)

试试这个

<mat-select placeholder="Select Events" [formControl]="selectEventitems" [(ngModel)]="selectedEventValue" (change)="onEventsChange($event)" (focus)="onEventfocus($event)" multiple>
     <mat-option class="select-all">Select All</mat-option>
     <mat-option *ngFor="let event of getAllEvents" [value]="event.eventrpt_id">{{event.eventrpt_id}} - {{event.descr}}</mat-option>
</mat-select>