Angular 2. 什么渲染速度更快:[ngClass] 或 class="{{}}"? [英] Angular 2. What is faster to render: [ngClass] or class="{{}}"?
本文介绍了Angular 2. 什么渲染速度更快:[ngClass] 或 class="{{}}"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么渲染速度更快?
one
或
<div class="ololo {{myVar ? 'my-class': ''}}">another</div>
或者其他方式?
解决方案
我做了一些研究,可以肯定地说这种方法
one
工作速度比
慢3倍<div class="ololo {{myVar ? 'my-class': ''}}">another</div>
请看演示
https://stackblitz.com/edit/angular-fvtzck
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?
解决方案
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
这篇关于Angular 2. 什么渲染速度更快:[ngClass] 或 class="{{}}"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文