|
2 | 2 |
|
3 | 3 | function classDirective(name, selector) {
|
4 | 4 | name = 'ngClass' + name;
|
5 |
| - return ['$interpolate', function($interpolate) { |
6 |
| - return function(scope, element, attr) { |
7 |
| - // Reusable function for re-applying the ngClass |
8 |
| - function reapply(newVal, oldVal) { |
9 |
| - if (selector === true || scope.$index % 2 === selector) { |
10 |
| - if (oldVal && (newVal !== oldVal)) { |
11 |
| - if (isObject(oldVal) && !isArray(oldVal)) |
12 |
| - oldVal = map(oldVal, function(v, k) { if (v) return k }); |
13 |
| - element.removeClass(isArray(oldVal) ? oldVal.join(' ') : oldVal); |
14 |
| - } |
15 |
| - if (isObject(newVal) && !isArray(newVal)) |
16 |
| - newVal = map(newVal, function(v, k) { if (v) return k }); |
17 |
| - if (newVal) element.addClass(isArray(newVal) ? newVal.join(' ') : newVal); |
| 5 | + return ngDirective(function(scope, element, attr) { |
| 6 | + // Reusable function for re-applying the ngClass |
| 7 | + function reapply(newVal, oldVal) { |
| 8 | + if (selector === true || scope.$index % 2 === selector) { |
| 9 | + if (oldVal && (newVal !== oldVal)) { |
| 10 | + if (isObject(oldVal) && !isArray(oldVal)) |
| 11 | + oldVal = map(oldVal, function(v, k) { if (v) return k }); |
| 12 | + element.removeClass(isArray(oldVal) ? oldVal.join(' ') : oldVal); |
18 | 13 | }
|
19 |
| - }; |
20 |
| - scope.$watch(attr[name], reapply, true); |
21 |
| - |
22 |
| - // Watch class attribute for changes |
23 |
| - if (attr['class']) { |
24 |
| - var interpolateFn = $interpolate(attr['class'], true); |
25 |
| - scope.$watch(interpolateFn, function(newClass, oldClass) { |
26 |
| - // Reapply ngClass |
27 |
| - var ngClass = scope.$eval(attr[name]); |
28 |
| - reapply(ngClass, ngClass); |
29 |
| - }); |
| 14 | + if (isObject(newVal) && !isArray(newVal)) |
| 15 | + newVal = map(newVal, function(v, k) { if (v) return k }); |
| 16 | + if (newVal) element.addClass(isArray(newVal) ? newVal.join(' ') : newVal); |
30 | 17 | }
|
31 |
| - |
32 | 18 | };
|
33 |
| - }]; |
| 19 | + scope.$watch(attr[name], reapply, true); |
| 20 | + |
| 21 | + attr.$observe('class', function(value) { |
| 22 | + var ngClass = scope.$eval(attr[name]); |
| 23 | + reapply(ngClass, ngClass); |
| 24 | + }); |
| 25 | + }); |
34 | 26 | }
|
35 | 27 |
|
36 | 28 | /**
|
|
0 commit comments