diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index 79c55d7abdd6..7794f293670a 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -26,13 +26,15 @@ function classDirective(name, selector) { } - function ngClassWatchAction(newVal, oldVal) { + var oldVal = undefined; + function ngClassWatchAction(newVal) { if (selector === true || scope.$index % 2 === selector) { if (oldVal && (newVal !== oldVal)) { removeClass(oldVal); } addClass(newVal); } + oldVal = newVal; } diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 4a53030bd21f..6fcfc9f92f28 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -235,6 +235,15 @@ describe('ngClass', function() { expect(element.hasClass('too')).toBeFalsy(); })); + it('should not mess up class application due to observing an interpolated class attribute', inject(function($rootScope, $compile) { + $rootScope.foo = true; + $rootScope.$watch("anything", function() { + $rootScope.foo = false; + }); + element = $compile('
')($rootScope); + $rootScope.$digest(); + expect(element.hasClass('foo')).toBeFalsy(); + })); it('should update ngClassOdd/Even when model is changed by filtering', inject(function($rootScope, $compile) { element = $compile('