在selection之内/之后更改选定的mat-chips

问题描述 投票:0回答:1

概念是,我想根据选择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方法内部更改选择值。

情况就是这样。选择默认过滤器。选择其他过滤器后,应取消选择默认过滤器。可以选择多个其他过滤器。如果选择了默认过滤器,则应取消选择所有其他过滤器。

html angular typescript
1个回答
0
投票

深入挖掘后,似乎不再在芯片上使用(selectionChange)修复程序,而是在自定义(click)方法中更改选择并更新过滤器。

© www.soinside.com 2019 - 2024. All rights reserved.