import { Injectable } from "@angular/core"; import { Subject } from 'rxjs/Subject'; import { Observable } from 'rxjs/Observable'; export const light: string = "light"; export const dark: string = "dark"; @Injectable() export class CmThemeService { public defaultTheme: string; private _currentTheme: string; private themeSource = new Subject(); public missionTheme$: Observable; constructor() { this.missionTheme$ = this.themeSource.asObservable(); this.defaultTheme = light; } public get currentTheme(): string { return this._currentTheme; } public use(themeName: string): void { document.documentElement.setAttribute('class', "theme-" + themeName); this._currentTheme = themeName; this.themeSource.next(themeName); } }