繁体   English   中英

ViewEncapsulation.ShadowDom 根本不渲染 css

[英]ViewEncapsulation.ShadowDom not rendering css at all

我正在尝试使用 ViewEncapsulation.ShadowDom 而我的 css 没有得到渲染,我在这里做错了什么,只有内联 css 被应用,这可能是什么原因。请建议。我不能分享代码,因为它是机密的.

编辑:我试过下面的例子

app.component.css

.test{
    background: green;
}

app.component.html

<p class="test"> HELLO</p>

app.component.ts

import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation:ViewEncapsulation.ShadowDom
})
export class AppComponent {
  title = 'app';
}

但在上面的示例中,它是从 ShadowDom 的 css 文件呈现的。

如果我没记错的话,这正是“ShadowDom”选项所做的。 它确实创建了一个 shadow dom 并封装了 styles,因此只考虑了组件 styles 而没有考虑全局/默认 styles。

Angular - 查看-封装

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM