From cb34293c1188ab76c1e0ced67e101173d7380dc8 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Tue, 9 Aug 2011 18:24:56 -0700 Subject: [PATCH 1/2] fix(directives): make ng:class-even/odd work with ng:class Closes #508 --- src/directives.js | 3 +++ test/directivesSpec.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/directives.js b/src/directives.js index 4712f250c097..0659f13679e5 100644 --- a/src/directives.js +++ b/src/directives.js @@ -596,8 +596,11 @@ function ngClass(selector) { return function(element) { this.$observe(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 a05861ae9f4f..be06bc6cfe78 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -225,6 +225,22 @@ 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('