How do I change the body class via the root component?
@Component({
selector: \"app\",
directives: [ROUTER_
One way that doesn't depend on direct DOM manipulation is, to make the tag the app element by using body as selector and use host-binding to update the app elements classes.
@Component({
selector: 'body',
host: {'[class.someClass]':'someField'}
})
export class AppElement implements AfterViewInit {
someField: bool = false;
// alternatively to the host parameter in `@Component`
// @HostBinding('class.someClass') someField: bool = false;
ngAfterViewInit() {
someField = true; // set class `someClass` on ``
}
}