isChecked = false; isIndeterminate = false;
onIndeterminateChange(event) { this.isIndeterminate = event; if (this.isIndeterminate) { this.isChecked = false; } }
.mat-checkbox-checked { .mat-checkbox-background, .mat-checkbox-frame { background-color: $mat-color-primary; } }
.mat-checkbox-indeterminate { .mat-checkbox-background, .mat-checkbox-frame { background-color: $mat-color-primary; } }
例如,在 app.module.ts 文件中:
import { MatCheckboxModule } from '@angular/material/checkbox'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({ imports: [ MatCheckboxModule, BrowserAnimationsModule, ... ], ... }) export class AppModule { }