gpt4 book ai didi

angularjs - 带有绑定(bind)的 ng-style 或 style 属性?哪个更好?哪个更快?有什么不同?

转载 作者:行者123 更新时间:2023-12-03 10:38:04 25 4
gpt4 key购买 nike

我正在优化我的大型应用程序。我对以下两种方法感到困惑,请帮助确定哪种方法更快。

内联样式属性

<div style="background-color:{{item.color}}"></div>

使用 ng 风格
<div ng-style="{'background-color':item.color}"></div>

使用一次式
<div once-style="{'background-color':item.color}"></div>

备注 : 对于 once-style ,我使用了 AngularOnce 指令。

提前致谢。请告诉我哪个更快以及为什么。

最佳答案

Angular 1.3 之后可以使用一次性绑定(bind)。

您可以在不依赖第三方库的情况下这样做:

<div ng-style="::{'background-color': item.color}"></div>

我没有测量性能,但我很确定它比没有冒号更好。

关于angularjs - 带有绑定(bind)的 ng-style 或 style 属性?哪个更好?哪个更快?有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22403107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com