From 7ec8a89362f7010f2b0f5fb73a644dab789ce010 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Tue, 9 Aug 2011 18:24:56 -0700 Subject: fix(directives): make ng:class-even/odd work with ng:class Closes #508 --- src/directives.js | 3 +++ test/directivesSpec.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/directives.js b/src/directives.js index 8ba5bace..937d0cca 100644 --- a/src/directives.js +++ b/src/directives.js @@ -546,8 +546,11 @@ function ngClass(selector) { return function(element) { this.$watch(function(scope) { 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); } }); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 1a02e318..488ebaa2 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -217,6 +217,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('