我正在尝试单击 mat-select multiple 中的按钮来实现,一个选项应该被取消选中,并且应该从选中的列表中删除。
为了删除选定的选项,我编写了如下代码:
垫选择选项:
<mat-form-field class="full-width">
<mat-select class="multiple-location-list-search-wrapper full-width" #mulLoc required placeholder="Locations" multiple>
<mat-option *ngFor="let l of locationsBasedOnPropertyType; let i = index" class="multiple-field-box" [hidden]="tempLocations[i]"
[value]="l">
{{ l.value }}
</mat-option>
</mat-select>
</mat-form-field>
删除按钮:
<span (click)="deleteLocation(i, mulLoc);">Delete Location</span>
<p>
<strong>{{mulLoc.value[i].value}}</strong>
</p>
删除功能:
deleteLocation(index, multipleLocation){
multipleLocation.selected[index]._selected = false;
multipleLocation.selected[index]._active = false;
multipleLocation.selected.splice(index,1);
multipleLocation.value.splice(index,1);
}
通过上面的实现,我可以从selected
&value
数组中删除选项,但它没有反映在 Material UI 中。位置选项没有被取消选中。
是否有任何黑客或内部方法可以做到这一点?
提前致谢!