Estoy haciendo un SPA
con soporte para dark-mode
pero me carga el nombre de la variable y no el valor
export class AppComponent implements OnInit {
title = 'App-title';
ngOnInit(){
var local = localStorage.getItem("theme") || "light-theme";
this.loadStyle(local == "light-theme" ? "light-theme":"dark-theme");
}
constructor(@Inject(DOCUMENT) private document: Document) {}
loadStyle(styleName: string) {
const head = this.document.getElementsByTagName('head')[0];
let themeLink = this.document.getElementById(
'client-theme'
) as HTMLLinkElement;
if (themeLink) {
themeLink.href = styleName;
} else {
const style = this.document.createElement('link');
style.id = 'client-theme';
style.rel = 'stylesheet';
style.href = `${styleName}`;
head.appendChild(style);
}
}
}