I have a component with a stylesheet that loads correctly like this:
@Component({
selector: \'open-account\',
styleUrls: [\'open-account.component.scss\'
The only way I found it works is to do this:
addStyleSheet() {
var headID = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.id = 'widget_styles';
headID.appendChild(link);
link.href = './app/open-account/open-account-widget-styles.component.css';
}
ngOnInit() {
this.addStyleSheet();
}
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({
})
export class SomeComponent {
constructor (@Inject(DOCUMENT) private document) { }
LightTheme() {
this.document.getElementById('theme').setAttribute('href', 'light-theme.css');
DarkTheme() {
this.document.getElementById('theme').setAttribute('href', 'dark-theme.css');
}
}