@@ -150,10 +150,11 @@ abstract class _NgClassBase {
150
150
final NgAnimate _animate;
151
151
var previousSet = [];
152
152
var currentSet = [];
153
+ Watch _watch;
153
154
154
-
155
- _NgClassBase ( this .element, this .scope, this .mode, this .nodeAttrs, this ._parser, this ._animate)
156
- {
155
+ _NgClassBase ( this .element, this .scope, this .mode, this .nodeAttrs,
156
+ this ._parser, this ._animate)
157
+ {
157
158
var prevClass;
158
159
159
160
nodeAttrs.observe ('class' , (String newValue) {
@@ -165,9 +166,8 @@ abstract class _NgClassBase {
165
166
}
166
167
167
168
set valueExpression (currentExpression) {
168
- // this should be called only once, so we don't worry about cleaning up
169
- // watcher registrations.
170
- scope.watch (_parser (currentExpression, collection: true ), (current, _) {
169
+ if (_watch != null ) _watch.remove ();
170
+ _watch = scope.watch (_parser (currentExpression, collection: true ), (current, _) {
171
171
currentSet = _flatten (current);
172
172
_handleChange (scope.context[r'$index' ]);
173
173
}, readOnly: true );
@@ -177,10 +177,8 @@ abstract class _NgClassBase {
177
177
if (oldIndex == null || mod != oldIndex % 2 ) {
178
178
if (mod == mode) {
179
179
currentSet.forEach ((css) => _animate.addClass (element, css));
180
- //element.classes.addAll(currentSet);
181
180
} else {
182
181
previousSet.forEach ((css) => _animate.removeClass (element, css));
183
- //element.classes.removeAll(previousSet);
184
182
}
185
183
}
186
184
}, readOnly: true );
@@ -191,18 +189,18 @@ abstract class _NgClassBase {
191
189
if (mode == null || (index != null && index % 2 == mode)) {
192
190
previousSet.forEach ((css) {
193
191
if (! currentSet.contains (css)) {
194
- _animate.removeClass (element, css);
192
+ _animate.removeClass (element, css);
195
193
} else {
196
194
element.classes.remove (css);
197
195
}
198
196
});
199
197
200
198
currentSet.forEach ((css) {
201
199
if (! previousSet.contains (css)) {
202
- _animate.addClass (element, css);
200
+ _animate.addClass (element, css);
203
201
} else {
204
202
element.classes.add (css);
205
- }
203
+ }
206
204
});
207
205
}
208
206
@@ -225,7 +223,7 @@ abstract class _NgClassBase {
225
223
return classes.keys.where ((key) => toBool (classes[key])).toList ();
226
224
}
227
225
if (classes is String ) return classes.split (' ' );
228
- throw
229
- 'ng-class expects expression value to be List, Map or String, got $classes ' ;
226
+ throw 'ng-class expects expression value to be List, Map or String, '
227
+ ' got $classes ' ;
230
228
}
231
229
}
0 commit comments