重點是,主題通常只是一些不同的顏色。您可以將所有主題添加到一個CSS。 my-app > .dark
獲取不同的顏色,並且該類將在代碼中動態添加。
這裏有一個更詳細的例子,我如何使用它:
APP-theme.scss:
@import '[email protected]/material/theming';
@include mat-core();
$words-app-primary: mat-palette($mat-teal, 300);
$words-app-secondary: mat-palette($mat-indigo, 500);
$words-app-warn: mat-palette($mat-red, 500);
$words-app-theme: mat-light-theme($words-app-primary, $words-app-secondary, $words-app-warn);
@include angular-material-theme($words-app-theme);
app-words-root > md-sidenav-container.dark {
$words-app-theme-dark: mat-dark-theme($words-app-primary, $words-app-secondary, $words-app-warn);
@include angular-material-theme($words-app-theme-dark);
}
app.component.html:
<md-sidenav-container [class.dark]="useDarkTheme"> ... </md-sidenav-container>
非角度版
app.component.js
import { DOCUMENT } from '@angular/platform-browser';
class AppComponent {
constructor(@Inject(DOCUMENT) document: any) {
let head = document.getElementsByTagName('head')[0];
let link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'assets/dark_room.css'; // you may want to get this from local storage or location
head.appendChild(link);
}
}
您是否試過這種方法? 讓您的後端根據URL參數生成不同的index.html。 – Niklas
@Niklas我認爲這可能是一種方法,但我不知道如何。因爲設置URL參數通常在.ts文件中完成,但index.html沒有。 –