I have created a light and dark theme from the kendo theme builder tool. I would like to switch the themes on the fly in my angular app. I managed to do that, however, the charts dont seem to like the new theme. Other controls seem to work fine. I am switching href of the link tag on the fly. Below is a snippet of the code I used.
@Component({
selector: 'css-loader',
template: `<link rel="stylesheet" type="text/css" [href]="path" />`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CssLoaderComponent {
public theme: string = environment.theme;
cssPath: any;
constructor(
public sanitizer: DomSanitizer,
private themeService: SidenavService,
private cd: ChangeDetectorRef,
private router: Router
) {
this.themeService.toggleState$.subscribe((val) => {
this.theme = this.theme === 'light-theme' ? 'dark-theme' : 'light-theme';
this.cssPath = `assets/themes/${this.theme}/${this.theme}.css`;
this.cd.markForCheck();
});
}
set path(path) {
this.cssPath = path;
}
get path() {
return this.sanitizer.bypassSecurityTrustResourceUrl(this.cssPath);
}
}