我有一个app.module.ts
其中包含一个称为_colors.scss
的部分SCSS文件。这个文件包含一个名为颜色,如:如何让Angular2子组件访问父母的SCSS样式?
$white: #FFFFFF
等等。
这里是组分:
import { Component, ViewEncapsulation } from '@angular/core';
import { ApiService } from './shared';
@Component({
selector: 'my-app', // <my-app></my-app>
templateUrl: './app.component.html',
styles: [ require('./app.component.imports.scss')],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
url = 'https://github.com/preboot/angular2-webpack';
constructor(private api: ApiService) {
// Do something with api
}
}
./app.component.imports.scss
里面是@import "../style/app.scss";
具有@import "../style/global-vars/_colors.scss"
它里面。
当我加载了我得到的Jetpack的,并在浏览器控制台中的编译错误另一条路线:
VM3358:1 Uncaught Error: Module build failed:
color: $sharp-blue;
^
Undefined variable: "$sharp-blue".
in /Users/username/Local Repo/project/retail-ui/src/style/app.scss (line 35, column 10)
做款式封装一些阅读我会通过设置encapsulation: ViewEncapsulation.None
想到以后这种风格将可在所有儿童组件中,但情况并非如此?
如何获得_colors.scss
部分加载并在我的子组件中可用?
它与封装无关。组件的SCSS需要访问变量。变量不存在于CSS输出中。因此,包含变量的SCSS文件应该在每个使用变量的文件中导入。 – estus