概念是,我想根据选择mat-chips
来过滤页面上显示的信息。
HTML:
<mat-chip-list [multiple]="true">
<mat-chip
class="item-filter-mat-chip"
*ngFor="let itemFilter of itemFilters"
[selectable]="true"
[selected]="itemFilter.selected"
[value]="itemFilter"
(selectionChange)="updateItemFilter($event)"
(click)="chip.toggleSelected()"
#chip="matChip">
{{itemFilter.displayValue}}
</mat-chip>
</mat-chip-list>
TypeScript项:
export interface ItemFilter {
itemType: ItemType[];
displayValue: string;
selected: boolean;
}
但是,如果未选择所有其他芯片,则我希望mat-chips
之一成为“默认”。但是,似乎必须在updateItemFilter
中进行选择更改的逻辑,然后创建ExpressionChangedAfterItHasBeenCheckedError
。这是因为我试图在selectionChange
方法内部更改选择值。
情况就是这样。选择默认过滤器。选择其他过滤器后,应取消选择默认过滤器。可以选择多个其他过滤器。如果选择了默认过滤器,则应取消选择所有其他过滤器。
深入挖掘后,似乎不再在芯片上使用(selectionChange)修复程序,而是在自定义(click)方法中更改选择并更新过滤器。