How to change MatChip selected property? I wan't on click to select/deselect chip (also it have to change chip color.) What I tried:
html:
<mat-chip-list>
<mat-chip *ngFor="let label of item.labels"
#lbl (click)="selectChip(lbl)">
{{label}}
</mat-chip>
</mat-chip-list>
ts:
selectChip(item: MatChip) {
item.selected ? item.deselect() : item.select();
}
On click it throws
ERROR TypeError: item.select is not a function
How to solve it?
There isn't a select() or deselect() method, there is just the selected getter and setter functions, so you can solve it like this:
Hope this helps.
If you use this html (please notice #lbl="matChip"):
Your
selectChip
method will receive a MatChip and then you can do the following: