我正在尝试在两个自定义主题之间切换。但是,我的页面上只有一些项目打开了切换点击。如何使其他元素也切换,例如边框、文本和悬停颜色?
索引.html
<body class="DefaultTheme">
<app-root></app-root>
</body>
app.component.html
<div>
<mat-slide-toggle name="toggle" (click)="changeTheme()">Change theme</mat-slide-toggle>
</div>
app.component.ts
export class AppComponent{
changeTheme() {
if (document.body.classList.contains("DefaultTheme")) {
document.body.classList.remove("DefaultTheme");
document.body.classList.add("CustomTheme");
}
else {
document.body.classList.remove("CustomTheme");
document.body.classList.add("DefaultTheme");
}
}
}
主题.scss
@import '~@angular/material/theming';
@include mat-core();
$app-primary: mat-palette($mtb-pallete, 500);
$app-accent: mat-palette($mtb-pallete, 550);
$app-warn: mat-palette($mat-red);
$app-theme: mat-light-theme($app-primary,$app-accent,$app-warn);
$primary: mat-color($app-primary);
$accent: mat-color($app-accent);
.DefaultTheme {
@include angular-material-theme($app-theme);
}
$alt-primary: mat-palette($mtb-pallete, 590);
$alt-accent: mat-palette($mtb-pallete, 580);
$alt-warn: mat-palette($mat-red);
$alt-theme: mat-light-theme($alt-primary, $alt-accent, $alt-warn);
$primary: mat-color($alt-primary);
$accent: mat-color($alt-accent);
.CustomTheme {
@include angular-material-theme($alt-theme);
}