【发布时间】:2022-01-23 09:24:24
【问题描述】:
我目前在 ngFor 中有一些自定义过滤器芯片,目前我将它们设置为一次只允许一个芯片在您单击它时更改背景颜色。我想更改此设置,以便我可以选择多个芯片并让其中多个芯片在选择时更改背景颜色。我应该如何处理?
HTML:
<div *ngFor="let category of categories; let i = index" class=" filter-chips px-3"
(click)="active = i; chipAdded(category)" [ngClass]="active === i ? 'chip-clicked': '' ">
{{category}}
</div>
组件:
active: any;
CSS:
.filter-chips {
min-width: 50px;
height: 30px;
background-color: grey;
border: 1px solid $grey-04;
box-sizing: border-box;
border-radius: 24px;
text-align: center;
color: $grey-02 !important;
cursor: pointer;
}
.chip-clicked {
background-color: green;
color: white !important;
border-color: white !important;
}
【问题讨论】:
标签: javascript html css angular typescript