[英]What is the cost of watching a template reference value in Angular
目前使用 Angular 8,最終得到了這樣的代碼。
<div [style.height.px]="dynamicHeightComponent.offsetHeight">
</div>
<div #dynamicHeightComponent>
...
</div>
這是否會影響性能,如果是,我們如何才能獲得更好的實現。
從模板引用中讀取值有時可能是一個性能問題,屬性 offsetHeight 肯定會影響性能。 因為當試圖讀取 offsetHeight 值時,瀏覽器會強制重排布局。
因此,這取決於您正在閱讀的屬性。 檢查此列表https://gist.github.com/paulirish/5d52fb081b3570c81e3a
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.