angular - Angular: setting ViewEncapsulation.None globally
问题描述
In my project, Angular adds css classes to HTML elements and components at runtime :
<div class="ng-tns-c99-6">..</div>
I've tried :
encapsulation: ViewEncapsulation.None
but it still adds the CSS class at runtime.
I found this answer here and tried to set ViewEncapsulation.None globally, but this doesn't affect it either, the CSS classes are still being added.
Is there a way to turn it off?
解决方案
It is not possible to set ViewEncapsulation
globally. Issue 18346 on GitHub suggests to allow setting it at the module level. The status of the issue is Open
at the present moment.
Set ViewEncapsulation per module #18346
Current behavior
Currently, we set the view encapsulation at the component level.
@Component({ selector: 'song-track', encapsulation: ViewEncapsulation.Native }) Meaning that if I want to use native Shadow DOM throughout my app, I have to add that bit of configuration to every single component.
Expected behavior
It would be great if I could set it at the module level.
@NgModule({ imports: [...], declarations: [...], providers: [ ... { provide: ViewEncapsulationMode, useValue: ViewEncapsulation.Native }, ... ], bootstrap: [AppComponent] }) export class AppModule { }
推荐阅读
- python - 使用蓝图的 Flask 路由不起作用,只有 '/' 路由在 Ubuntu 上有效,但在 Windows 上一切都很好
- ruby-on-rails - 从rails中创建的记录中获取ID
- azure - Azure 应用服务 - 应用的免费 ssl 证书是否有限制?
- mysql - 在 Spring Boot 中,希望在输出中显示实体类中的字段但不需要输入
- java - 在 BaseActivity 的子类中显示工具栏
- constraints - 雪花的唯一约束有什么意义?
- mailgun - mailgun 通过 SMTP 发送模板电子邮件
- c# - 如何使代理随时间变化 C# .NET Framework
- php - 函数渲染使网站速度减慢 500%!任何人都可以解决这个问题吗?
- java - As400 运行个人 JRE