【发布时间】:2016-12-20 07:30:15
【问题描述】:
我想为我的网站应用一些全局样式(body、h1、h2、h3 等)。
要使用 Angular2 执行此操作,需要设置组件的 view encapsultation:encapsulation: ViewEncapsulation.None。
示例:
@Component({
selector: 'app-root',
templateUrl: template(),
styleUrls: ['global.scss', 'app.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
title = 'Hello world!';
}
问题是这个封装规则适用于所有这个组件样式表,这意味着我必须有一个单独的组件只用于全局样式。
是否有另一种方法可以做到这一点而不需要额外的组件并且不需要编辑 Angular-CLI 的构建配置?
(我正在使用angular/core 2.0.0-rc.5 和angular-cli 1.0.0-beta.11-webpack.2)
【问题讨论】:
-
为什么不在 index.html 中添加一个全局样式表?我的意思是,风格的东西很好而且有光泽,但你必须使用它并没有什么特别的。
-
因为 Angular-CLI 没有检测到这一点,因此不会将其包含在构建中。除非我弄错了,否则所有资源都必须在脚本中导入或引用。
标签: css angular angular-cli