当用户选择它时,我一直试图在垫片上触发背景颜色变化。已经能够按照这篇文章https://stackoverflow.com/questions/47219078/cant-change-angular2-material-matchip-selected-state
切换芯片的状态在任何地方都没有提及它。 这就是我到目前为止所做的:
<mat-chip-list formControlName="packageName">
<mat-basic-chip *ngFor="let pkg of packages" #lbl selected="false" (click)="selectedPkg(lbl)">
{{pkg.cbsCode}}<br>
</mat-basic-chip>
</mat-chip-list>
TS
selectedPkg(pkg: MatChip) {
pkg.selected = !pkg.selected;
pkg.color='warn';
console.log(pkg.value);
// this.form.patchValue({packageName: pkg});
}