Angular 2. What is faster to render: [ngClass] or class=“{{}}”?

泄露秘密 提交于 2020-01-24 15:29:47

问题


What will render faster?

  <div class="ololo" [ngClass]="{'my-class': myVar}">one</div>

or

  <div class="ololo {{myVar ? 'my-class': ''}}">another</div>

or some another way?


回答1:


I did some research and can surely say that this approach

<div class="ololo" [ngClass]="{'my-class': myVar}">one</div>

works about 3 times slower than

<div class="ololo {{myVar ? 'my-class': ''}}">another</div>

please see a demo

https://stackblitz.com/edit/angular-fvtzck



来源:https://stackoverflow.com/questions/46605252/angular-2-what-is-faster-to-render-ngclass-or-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!