8
8
9
9
function classDirective ( name , selector ) {
10
10
name = 'ngClass' + name ;
11
+ var indexWatchExpression ;
11
12
12
13
return [ '$parse' , function ( $parse ) {
13
14
return {
@@ -32,7 +33,14 @@ function classDirective(name, selector) {
32
33
}
33
34
34
35
if ( name !== 'ngClass' ) {
35
- scope . $watch ( '$index' , ngClassIndexWatchAction ) ;
36
+ if ( ! indexWatchExpression ) {
37
+ indexWatchExpression = $parse ( '$index' , function moduloTwo ( $index ) {
38
+ // eslint-disable-next-line no-bitwise
39
+ return $index & 1 ;
40
+ } ) ;
41
+ }
42
+
43
+ scope . $watch ( indexWatchExpression , ngClassIndexWatchAction ) ;
36
44
}
37
45
38
46
scope . $watch ( watchExpression , watchAction , isOneTime ) ;
@@ -76,22 +84,17 @@ function classDirective(name, selector) {
76
84
return classesToUpdate . join ( ' ' ) ;
77
85
}
78
86
79
- function ngClassIndexWatchAction ( $index ) {
80
- // eslint-disable-next-line no-bitwise
81
- var newModulo = $index & 1 ;
82
-
83
- if ( newModulo !== oldModulo ) {
84
- // This watch-action should run before the `ngClass[OneTime]WatchAction()`, thus it
85
- // adds/removes `oldClassString`. If the `ngClass` expression has changed as well, the
86
- // `ngClass[OneTime]WatchAction()` will update the classes.
87
- if ( newModulo === selector ) {
88
- addClasses ( oldClassString ) ;
89
- } else {
90
- removeClasses ( oldClassString ) ;
91
- }
92
-
93
- oldModulo = newModulo ;
87
+ function ngClassIndexWatchAction ( newModulo ) {
88
+ // This watch-action should run before the `ngClass[OneTime]WatchAction()`, thus it
89
+ // adds/removes `oldClassString`. If the `ngClass` expression has changed as well, the
90
+ // `ngClass[OneTime]WatchAction()` will update the classes.
91
+ if ( newModulo === selector ) {
92
+ addClasses ( oldClassString ) ;
93
+ } else {
94
+ removeClasses ( oldClassString ) ;
94
95
}
96
+
97
+ oldModulo = newModulo ;
95
98
}
96
99
97
100
function ngClassOneTimeWatchAction ( newClassValue ) {
0 commit comments