AngularJS,ng-class和带有角度表达式的类之间的区别?

时间:2022-06-09 12:10:12

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

以下两个代码片段之间有什么区别,代码1:

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

Code 2:

代码2:

<div ng-class=getClass()/>

1 个解决方案

#1


7  

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.

对于角度加载之前的第一个示例,您的类将字面上为“{{getClass()}}”。而在第二个例子中,div只有在第一个摘要的角度运行时才会有一个类。

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.

重新计算时可能会有一些细微差别,但Angular会保持最新状态。我在使用第一个方法与动画之前遇到了问题,因为ng-class有一些动画钩子。

#1


7  

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.

对于角度加载之前的第一个示例,您的类将字面上为“{{getClass()}}”。而在第二个例子中,div只有在第一个摘要的角度运行时才会有一个类。

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.

重新计算时可能会有一些细微差别,但Angular会保持最新状态。我在使用第一个方法与动画之前遇到了问题,因为ng-class有一些动画钩子。