angular雙向綁定數(shù)據(jù)页响,視圖不能及時(shí)更新時(shí)非洲,進(jìn)行強(qiáng)制更新
(1)從core中導(dǎo)入ChangeDetectorRef
(2)在構(gòu)造函數(shù)中注入private changeDetectorRef: ChangeDetectorRef
(3)在需要強(qiáng)制更新視圖時(shí)調(diào)用:this.changeDetectorRef.detectChanges();
dom新增節(jié)點(diǎn)后需要時(shí)間來(lái)更新dom結(jié)構(gòu),要獲取新的節(jié)點(diǎn)內(nèi)容需要等待數(shù)ms俯画,否則會(huì)出現(xiàn)無(wú)法獲取節(jié)點(diǎn)的情況析桥。