【发布时间】:2018-12-04 14:06:01
【问题描述】:
我有一个组件页面和相应的样式表,但是 component.scss 中的类不适用于该页面。没有错误,我仍然想知道为什么?
这是我的 product-detailpage.component.html
<div>
<h1>Product Detail Page</h1>
</div>
这是 .ts 文件
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {ProductdetailService} from '../productdetail.service';
@Component({
selector: 'app-product-detailpage',
templateUrl: './product-detailpage.component.html',
styleUrls: ['./product-detailpage.component.scss']
})
export class ProductDetailpageComponent implements OnInit {
constructor(private route: ActivatedRoute, private productData: ProductdetailService) {
this.route.params.subscribe(params => console.log(params));
}
ngOnInit() {
}
}
这是 .scss 文件
body{color:Red !important}
app-product-detailpage{
h1{color:red !important}
}
但是我注意到的一件事是,如果我对全局 styles.css 进行更改,它可以正常工作。只是为了检查我将身体颜色更改为绿色并且它可以工作。
我的 Angular 应用程序配置为使用 scss。可能是什么原因?有人可以建议吗?
【问题讨论】:
-
我有一个类似的问题,并使用“encapsulation.none”解决。我使用 rootViewRef 以编程方式渲染组件,所以它没有自己的 shadow dom。
-
请看这篇文章,上面有很多solition (angular.io/guide/component-styles)