【问题标题】:Angular 6-7 ViewEncapsulation.emulated prefixAngular 6-7 ViewEncapsulation.emulated 前缀
【发布时间】:2019-08-11 07:42:19
【问题描述】:

是否可以在 Angular 2-7 组件中启用 ViewEncapsulation.Emulated 时生成的标签添加前缀或后缀,它现在就像 [_ngContent-C0] 是否有设置让它执行类似 [_ngContent-C0-myApp] 的操作,所以添加自定义字符串到生成的类标签?

最好的问候

【问题讨论】:

    标签: angular angular6 angular2-template angular7


    【解决方案1】:

    如果您查看与 dom 渲染相关的 Angular 源代码 https://github.com/angular/angular/blob/master/packages/platform-browser/src/dom/dom_renderer.ts#L32 ,您会看到该属性具有固定模式并且不接受外部设置。所以我的猜测是,不,你不能,至少对于当前版本。并且最有可能的是,它永远不会公开这样的选项,因为它可能会导致非唯一标识符会破坏封装。

    更新:componentId是组件定义中定义的id,可以查看https://github.com/angular/angular/blob/master/packages/compiler/src/aot/compiler.ts#L266,可以看到是自增的。

    【讨论】:

    • 什么是组件短ID?我可以以某种方式设置它吗?
    猜你喜欢
    • 1970-01-01
    • 2019-01-27
    • 2015-11-28
    • 2019-03-26
    • 1970-01-01
    • 2017-06-07
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多