ng-style or style attribute with binding? Which is better? Which is faster? What is the difference?

后端 未结 2 1435
青春惊慌失措
青春惊慌失措 2021-01-01 09:38

I am optimizing my large application. I am confused between following two approach, please help to decide which one is faster.

Inline style attributes

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 10:09

    Since you are optimizing your considerably large application, performance is definitely under question and I think ngStyle performs better as it sets up watch on the model and will update the view only if the model has changed.

    So I would go with ngStyle or onceStyle depending on your scenario:

    Using {{}} will make Angular update the binding every digest cycle, even if the value has not changed.

提交回复
热议问题