Angular应用页面里_ngcontent属性的生成逻辑
发布日期:2021-06-30 14:41:20 浏览次数:2 分类:技术文章

本文共 1138 字,大约阅读时间需要 3 分钟。

我们打开一个Angular应用,发现其渲染页面里的DOM元素,包含了形如_nghost-, 以及_ngcontent-这种属性。

这些属性在platform-browser.js的DomRenderer2里生成,具体位置在shimContentAttribute和shimHostAttribute函数内:

class EmulatedEncapsulationDomRenderer2 extends DefaultDomRenderer2 {
/** * @param {?} eventManager * @param {?} sharedStylesHost * @param {?} component * @param {?} appId */ constructor(eventManager, sharedStylesHost, component, appId) {
super(eventManager); this.component = component; /** @type {?} */ const styles = flattenStyles(appId + '-' + component.id, component.styles, []); sharedStylesHost.addStyles(styles); this.contentAttr = shimContentAttribute(appId + '-' + component.id); this.hostAttr = shimHostAttribute(appId + '-' + component.id); }

const COMPONENT_REGEX = /%COMP%/g;/** @type {?} */const NG_DEV_MODE = typeof ngDevMode === 'undefined' || !!ngDevMode;/** @type {?} */const COMPONENT_VARIABLE = '%COMP%';/** @type {?} */const HOST_ATTR = `_nghost-${
COMPONENT_VARIABLE}`;/** @type {?} */const CONTENT_ATTR = `_ngcontent-${
COMPONENT_VARIABLE}`;

更多Jerry的原创文章,尽在:“汪子熙”:

转载地址:https://jerry.blog.csdn.net/article/details/112391112 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Angular应用页面里appId的生成逻辑和位置
下一篇:Angular Component的renderer创建机制以及Angular版本号的确定方式

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年05月03日 21时26分47秒