css - Angular 6 not applying scss styles
问题描述
I have a component page and corresponding style sheet, however the classes in the component.scss dosen't apply to the page. There are no errors, I am still wondering why?
This is my product-detailpage.component.html
<div>
<h1>Product Detail Page</h1>
</div>
This is the .ts file
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() {
}
}
This is the .scss file
body{color:Red !important}
app-product-detailpage{
h1{color:red !important}
}
However one thing I noticed was if I make changes to the global styles.css it works fine. just to check I changed the body color to green and it works.
My angular app is configured to work with scss. what could be the reason? can some one suggest?
解决方案
您的 SCSS 不适用于您的 HTML 文件product-detailpage.component.html。
原因是 Angular 使用shadow DOM作为组件。这意味着标签在您的组件<body>
中<app-product-detailpage>
无处可寻。
推荐阅读
- python - 如何使用“for循环”将列表值添加到networkx节点?
- css - 我在这个 SASS for 循环中使用两个列表的逻辑有问题......我得到的错误是“索引超出了 `nth($list, $n)` 的范围”
- swift - 有没有办法在 SwiftUI 中与 Pull to Refresh 相反
- keras - 每 N 个批次计算直方图/嵌入
- reactjs - 无法使用前端 react/axios 将 encType="multipart/formdata" 的表单数据发送到后端节点/multer
- jquery - 使用服务器端处理对 DataTables 进行分页
- javascript - 使用css中的关键帧沿正方形方向移动圆圈
- c - 初始化器元素在 C 编译器中不是常量
- windows - 我无法使用此代码在我的活动目录中获取用户
- salesforce - 如何使用自定义设置在 Salesforce 中添加假期列表