AngularJS, difference between ng-class and class with angular expression?

北城以北 提交于 2019-12-05 11:08:54

问题


What is the difference between the following two code snippets,
Code 1:

<div class={{getClass()}}/>

Code 2:

<div ng-class=getClass()/>

回答1:


With the first example before angular loads your class will literally be "{{getClass()}}". While in the second example the div won't have a class until angular runs its first digest.

There might be some minor differences with when they are recalculated but Angular will keep both up to date. I've run into issues before using the first method with Animation as ng-class has some hooks into animation.



来源:https://stackoverflow.com/questions/24578501/angularjs-difference-between-ng-class-and-class-with-angular-expression

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