我有一组选定的位置和all_locations。如果该位置出现在选定的位置,我想在mat-select选项中设置为selected。
Users_loc=[username:'A1',
locations:{'A','B','C'}
]
all_loc=[location_name:'A',
location_name:'B',
location_name:'C',
location_name:'D',
location_name:'E',
location_name:'F',...,
location_name:'Y',
location_name:'Z']
<div class="form-controls">
<mat-form-field>
<mat-select mulitple (selectionChange)="regionSelectionChange($event.value)" placeholder="Region">
<mat-option *ngFor="let region of regions" [value]="region.location_name">{{region.location_name}}</mat-option>
</mat-select>
</mat-form-field>
</div>
我要在选型中选择A,B,C前面的复选标记。.
答案 0 :(得分:0)
在选择时,如果您正在获取像这样的数据:[A,B,C],则可以像这样通过[[ngModel)]传递这种类型的数组:
<mat-form-field>
<mat-select (selectionChange)="regionSelectionChange($event.value)" placeholder="Region" multiple [(ngModel)]="selectedData">
<mat-option *ngFor="let region of regions" [value]="region.location_name">{{region.location_name}}</mat-option>
</mat-select>
</mat-form-field>
在TS中:
selectedData = [A,B,C]