diff --git a/src/directives.js b/src/directives.js index 9aa0d57eb557..64a06359affb 100644 --- a/src/directives.js +++ b/src/directives.js @@ -571,9 +571,14 @@ function ngClass(selector) { var existing = element[0].className + ' '; return function(element){ this.$onEval(function(){ - if (selector(this.$index)) { - var value = this.$eval(expression); + var scope = this; + + if (selector(scope.$index)) { + var ngClassVal = scope.$eval(element.attr('ng:class') || ''); + if (isArray(ngClassVal)) ngClassVal = ngClassVal.join(' '); + var value = scope.$eval(expression); if (isArray(value)) value = value.join(' '); + if (ngClassVal && ngClassVal !== value) value = value + ' ' + ngClassVal; element[0].className = trim(existing + value); } }, element); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 22d3c84bb843..afb4e04fe71b 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -220,6 +220,50 @@ describe("directive", function(){ expect(e2.hasClass('even')).toBeTruthy(); }); + + it('should allow both ng:class and ng:class-odd/even on the same element', function() { + var scope = compile('