diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index 2b258a4ac1ec..0ab069399e94 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -78,7 +78,11 @@ function classDirective(name, selector) { updateClasses(oldClasses, newClasses); } } - oldVal = shallowCopy(newVal); + if (isArray(newVal)) { + oldVal = newVal.map(function(v) { return shallowCopy(v); }); + } else { + oldVal = shallowCopy(newVal); + } } } }; diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index a50f611e4b18..1d7cd1b56f16 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -409,6 +409,22 @@ describe('ngClass', function() { expect(e2.hasClass('even')).toBeTruthy(); expect(e2.hasClass('odd')).toBeFalsy(); })); + + it('should support mixed array/object variable with a mutating object', + inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); + + $rootScope.classVar = [{orange: true}]; + $rootScope.$digest(); + expect(element).toHaveClass('orange'); + + $rootScope.classVar[0].orange = false; + $rootScope.$digest(); + + expect(element).not.toHaveClass('orange'); + }) + ); + }); describe('ngClass animations', function() {