日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Angular ɵɵelementStart和ɵɵText的工作原理

發(fā)布時間:2023/12/19 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Angular ɵɵelementStart和ɵɵText的工作原理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我有一個Angular Component:

@Component({selector: "app-root",template: `<div cxFocuses>Painful</div>` }) export class AppComponent {}

Angular編譯器編譯后生成的JavaScript代碼:

這些??elementStart函數(shù)的執(zhí)行上下文:在templateFn里被調(diào)用:

單步調(diào)試下圖的第48行代碼:

即進(jìn)入??elementStart:

/*** Create DOM element. The instruction must later be followed by `elementEnd()` call.** \@codeGenApi* @param {?} index Index of the element in the LView array* @param {?} name Name of the DOM Node* @param {?=} attrsIndex Index of the element's attributes in the `consts` array.* @param {?=} localRefsIndex Index of the element's local references in the `consts` array.** Attributes and localRefs are passed as an array of strings where elements with an even index* hold an attribute name and elements with an odd index hold an attribute value, ex.:* ['id', 'warning5', 'class', 'alert']** @return {?}*/ function ??elementStart(index, name, attrsIndex, localRefsIndex) {/** @type {?} */const lView = getLView();/** @type {?} */const tView = getTView();/** @type {?} */const adjustedIndex = HEADER_OFFSET + index;ngDevMode &&assertEqual(getBindingIndex(), tView.bindingStartIndex, 'elements should be created before any bindings');ngDevMode && ngDevMode.rendererCreateElement++;ngDevMode && assertDataInRange(lView, adjustedIndex);/** @type {?} */const renderer = lView[RENDERER];/** @type {?} */const native = lView[adjustedIndex] = elementCreate(name, renderer, getNamespace());/** @type {?} */const tNode = tView.firstCreatePass ?elementStartFirstCreatePass(index, tView, lView, native, name, attrsIndex, localRefsIndex) :(/** @type {?} */ (tView.data[adjustedIndex]));setPreviousOrParentTNode(tNode, true);/** @type {?} */const mergedAttrs = tNode.mergedAttrs;if (mergedAttrs !== null) {setUpAttributes(renderer, native, mergedAttrs);}/** @type {?} */const classes = tNode.classes;if (classes !== null) {writeDirectClass(renderer, native, classes);}/** @type {?} */const styles = tNode.styles;if (styles !== null) {writeDirectStyle(renderer, native, styles);}appendChild(tView, lView, native, tNode);// any immediate children of a component or template container must be pre-emptively// monkey-patched with the component view data so that the element can be inspected// later on using any element discovery utility methods (see `element_discovery.ts`)if (getElementDepthCount() === 0) {attachPatchData(native, lView);}increaseElementDepthCount();if (isDirectiveHost(tNode)) {createDirectivesInstances(tView, lView, tNode);executeContentQueries(tView, tNode, lView);}if (localRefsIndex !== null) {saveResolvedLocalsInData(lView, tNode);} }

??elementStart函數(shù)內(nèi)部會動態(tài)創(chuàng)建div標(biāo)簽元素:

并作為app-root的子節(jié)點(diǎn),插入到DOM tree里。

div標(biāo)簽內(nèi)的text文本,也通過函數(shù)createTextNode動態(tài)創(chuàng)建的text標(biāo)簽來承載:

更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:

我有一個Angular Component:

@Component({selector: "app-root",template: `<div cxFocuses>Painful</div>` }) export class AppComponent {}

Angular編譯器編譯后生成的JavaScript代碼:

這些??elementStart函數(shù)的執(zhí)行上下文:在templateFn里被調(diào)用:

單步調(diào)試下圖的第48行代碼:

即進(jìn)入??elementStart:

/*** Create DOM element. The instruction must later be followed by `elementEnd()` call.** \@codeGenApi* @param {?} index Index of the element in the LView array* @param {?} name Name of the DOM Node* @param {?=} attrsIndex Index of the element's attributes in the `consts` array.* @param {?=} localRefsIndex Index of the element's local references in the `consts` array.** Attributes and localRefs are passed as an array of strings where elements with an even index* hold an attribute name and elements with an odd index hold an attribute value, ex.:* ['id', 'warning5', 'class', 'alert']** @return {?}*/ function ??elementStart(index, name, attrsIndex, localRefsIndex) {/** @type {?} */const lView = getLView();/** @type {?} */const tView = getTView();/** @type {?} */const adjustedIndex = HEADER_OFFSET + index;ngDevMode &&assertEqual(getBindingIndex(), tView.bindingStartIndex, 'elements should be created before any bindings');ngDevMode && ngDevMode.rendererCreateElement++;ngDevMode && assertDataInRange(lView, adjustedIndex);/** @type {?} */const renderer = lView[RENDERER];/** @type {?} */const native = lView[adjustedIndex] = elementCreate(name, renderer, getNamespace());/** @type {?} */const tNode = tView.firstCreatePass ?elementStartFirstCreatePass(index, tView, lView, native, name, attrsIndex, localRefsIndex) :(/** @type {?} */ (tView.data[adjustedIndex]));setPreviousOrParentTNode(tNode, true);/** @type {?} */const mergedAttrs = tNode.mergedAttrs;if (mergedAttrs !== null) {setUpAttributes(renderer, native, mergedAttrs);}/** @type {?} */const classes = tNode.classes;if (classes !== null) {writeDirectClass(renderer, native, classes);}/** @type {?} */const styles = tNode.styles;if (styles !== null) {writeDirectStyle(renderer, native, styles);}appendChild(tView, lView, native, tNode);// any immediate children of a component or template container must be pre-emptively// monkey-patched with the component view data so that the element can be inspected// later on using any element discovery utility methods (see `element_discovery.ts`)if (getElementDepthCount() === 0) {attachPatchData(native, lView);}increaseElementDepthCount();if (isDirectiveHost(tNode)) {createDirectivesInstances(tView, lView, tNode);executeContentQueries(tView, tNode, lView);}if (localRefsIndex !== null) {saveResolvedLocalsInData(lView, tNode);} }

??elementStart函數(shù)內(nèi)部會動態(tài)創(chuàng)建div標(biāo)簽元素:

并作為app-root的子節(jié)點(diǎn),插入到DOM tree里。

div標(biāo)簽內(nèi)的text文本,也通過函數(shù)createTextNode動態(tài)創(chuàng)建的text標(biāo)簽來承載:

更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:

總結(jié)

以上是生活随笔為你收集整理的Angular ɵɵelementStart和ɵɵText的工作原理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。