2
私はAngular 2 Materialアプリケーションを持っています。 そして私がしたいのは、単純なボタンbutton
をクリックするだけで、テーマを暗いから明るく切り替えることです。角度のある材質2.クリック時の明るさから暗い色への切り替え
どうすればいいですか?
app.component.html:あなたのmenu
で
私はAngular 2 Materialアプリケーションを持っています。 そして私がしたいのは、単純なボタンbutton
をクリックするだけで、テーマを暗いから明るく切り替えることです。角度のある材質2.クリック時の明るさから暗い色への切り替え
どうすればいいですか?
app.component.html:あなたのmenu
で
<div [class.dark-theme]="isDarkTheme">
<!--Your application content here-->
<md-menu #more="mdMenu">
<!--Your content here-->
<button md-menu-item (click)="changeTheme()">
Change Theme
</button>
</md-menu>
</div>
app.component.ts:
// import statements here
import {Component} from '@angular/core';
export class AppComponent {
// Initialize isDarkTheme to false
isDarkTheme: boolean = false;
// Your code here
changeTheme(): void {
if (this.isDarkTheme) {
this.isDarkTheme = false;
} else {
this.isDarkTheme = true;
}
}
}
theme.scss:
@import '[email protected]/material/core/theming/_all-theme';
@include mat-core();
.dark-theme {
// Dark theme
$app-dark-primary: mat-palette($mat-pink, 700);
$app-dark-accent: mat-palette($mat-blue-grey);
$app-dark-theme: mat-dark-theme($app-dark-primary, $app-dark-accent);
@include angular-material-theme($app-dark-theme);
}
私は、さらに私のアンギュラcli.jsonファイルに 'sometheme.scss'を追加すべきか? –
はい、追加する必要があります。 – Edric