[英]Angular 2+: change detection, the state between property-change and view-update
--------------更新---------------
ChangeDetectorRef.detectChanges()運行組件及其子組件的更改檢測器。 因此,它可能是一個解決方案。
--------------原始問題----------------
目的:我希望在組件中更新特定的dom元素后獲得通知。
結果: p的clientHeight仍然是先前的值,而不是最新的值。
預期結果 :最新值
可能的解決方案:
我的困惑:
changeProperty(this.text => { this.text = 'A long long text'; }).then( () => { // here is the state after the corresponding text is updated in the view })
或者哪個是解決這個問題的正確方法? 感謝任何想法!
沒有這樣的東西,我懷疑它會出現。
但是,您的特定問題可以以完全不同的方式解決。 只要你想控制text / html的渲染方式,就可以更容易地自己渲染它。
只需設置innerHTML,就會有適當的高度
changeText(para) {
para.innerHTML = 'long text';
console.log(para.clientHeight);
}
就是這樣。 請記住,在分配它之前使用innerText
或執行一些HTML innerText
可能更好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.