新聞中心
Angular form控件原生HTML代碼里ng-reflect-form屬性和其值的生成時(shí)機(jī)是什么,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
創(chuàng)新互聯(lián)作為成都網(wǎng)站建設(shè)公司,專(zhuān)注重慶網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),有關(guān)成都企業(yè)網(wǎng)站定制方案、改版、費(fèi)用等問(wèn)題,行業(yè)涉及廣告設(shè)計(jì)等多個(gè)領(lǐng)域,已為上千家企業(yè)服務(wù),得到了客戶(hù)的尊重與認(rèn)可。
簡(jiǎn)單的Component代碼:
import { Component } from '@angular/core';import { FormControl } from '@angular/forms';@Component({ selector: 'app-reactive-favorite-color', template: ` Favorite Color: })export class ReactFormComponent { favoriteColorControl = new FormControl('');}
如下圖所示:ng-reflect-form這個(gè)屬性運(yùn)行時(shí)是如何生成的?
bootstrap里調(diào)用_loadComponent:
changeDetectorRef的策略:RootViewRef:
ComponentRef指向的AppComponent,能看到Component的property:
loadComponent里顯式調(diào)用tick:
tick函數(shù)里進(jìn)行change detect:
Angular Component html里加了方括號(hào)的Directive,瀏覽器是無(wú)法識(shí)別的,在Angular core.js里,在執(zhí)行Component template實(shí)現(xiàn)函數(shù)時(shí),會(huì)調(diào)用Angular的??property函數(shù),將中括號(hào)包裹的Angular指令展開(kāi):Update a property on a selected element.
element指向input控件:
需要添加到input標(biāo)簽頁(yè)的屬性名稱(chēng)為form:
經(jīng)過(guò)normalizeDebugBindingValue里面的正則化處理完屬性form之后,返回的值:
ng-reflect-form
待寫(xiě)入input ng-reflect-form屬性的值:
為了避免value的值過(guò)于復(fù)雜時(shí),序列化生成的json字符床過(guò)大,污染了最后的原生html,在normalizeDebugBindingValue里只是簡(jiǎn)單的調(diào)用toString函數(shù):
// Limit the size of the value as otherwise the DOM just gets polluted.
這就是最后在Chrome開(kāi)發(fā)者工具里看到的[object Object]的由來(lái):
關(guān)于Angular form控件原生HTML代碼里ng-reflect-form屬性和其值的生成時(shí)機(jī)是什么問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
本文標(biāo)題:Angularform控件原生HTML代碼里ng-reflect-form屬性和其值的生成時(shí)機(jī)是什么
網(wǎng)站路徑:http://fisionsoft.com.cn/article/ghosij.html