简体   繁体   English

在 Angular 中观看模板参考值的成本是多少

[英]What is the cost of watching a template reference value in Angular

Currently using Angular 8, ended up with a code like this.目前使用 Angular 8,最终得到了这样的代码。

<div [style.height.px]="dynamicHeightComponent.offsetHeight">
</div>
<div #dynamicHeightComponent>
...
</div>

Is this a hit to performance, if it is, how can we get a better implementation.这是否会影响性能,如果是,我们如何才能获得更好的实现。

Reading a value from template reference sometimes can be a performance problem, the property offsetHeight definitely will affect the performance.从模板引用中读取值有时可能是一个性能问题,属性 offsetHeight 肯定会影响性能。 Because when trying to read the value offsetHeight browser will forcefully reflow the layout.因为当试图读取 offsetHeight 值时,浏览器会强制重排布局。

So it depends on which property you are reading.因此,这取决于您正在阅读的属性。 check this list https://gist.github.com/paulirish/5d52fb081b3570c81e3a检查此列表https://gist.github.com/paulirish/5d52fb081b3570c81e3a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM