我需要为我在 angular2 中开发的 Web 应用程序提供两个主题(红色、蓝色)。当我更改主题时,所有组件都应该反映它吗?
在 Angular2 中应用主题的最佳实践是什么?
您可以使用文件代币从 @angular/platform-browser 获取对所有 DOM 元素的访问权限,然后更改样式表源。下面是一个简单的例子。
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({})
export class SomeComponent {
constructor (@Inject(DOCUMENT) private document) { }
Light() {
this.document.getElementById('theme').setAttribute('href', 'light.css');
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)