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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年05月03日 21时26分47秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Python干货:表达式 i += x 与 i = i + x 等价吗?
2019-05-01
有了这些 Chrome 插件,效率提升10倍(建议收藏)
2019-05-01
Python 编码错误的本质原因
2019-05-01
Python 开发者都会遇到的错误:UnboundLocalError
2019-05-01
用 Python 送“爱心”
2019-05-01
理解HTTPS为什么安全前,先看看这些东西
2019-05-01
只有1%的程序员搞懂过浮点数陷阱
2019-05-01
Erlang 之父 Joe Armstrong 去世
2019-05-01
一名 Google 工程师的大数据处理经验
2019-05-01
30分钟学会pyecharts数据可视化
2019-05-01
从一个骗子身上学到的
2019-05-01
关于Python爬虫,这里有一条高效的学习路径
2019-05-01
Python学习指南,看这篇清晰多了!
2019-05-01
命名难,难于上青天
2019-05-01
史上最烂项目:苦撑12年,600多万行代码...
2019-05-01
没钱没公司,怎么做一款付费产品
2019-05-01
查询亿级数据毫秒级返回!Elasticsearch 是如何做到的?
2019-05-01
FastAPI 构建 API 服务,究竟有多快?
2019-05-01
为什么Quora选择用Python语言?
2019-05-01
一劳永逸学编程的方法
2019-05-01