我試圖在mat-select中單擊一個按鈕來實現多個選項,選項應該取消選中,並且應該從檢查列表中刪除。動態取消選中md-select angular 4.x中的多個選擇選項
去除所選的選項我寫我的代碼如下:
墊選擇選項:
<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中。位置選項沒有被取消選中。
是否有任何黑客或內部方法做同樣的事情?
在此先感謝!
我不想刪除選項,我只是想取消選中它。 –
哼好吧,[這個例子]怎麼樣(https://stackblitz.com/edit/material2-beta12-ygj9vj?file=app%2Fapp.component.ts) –