From bd97464275b03cb411b7eaae7a0ec7e5edd9275a Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Sun, 10 Apr 2016 00:22:50 +0200 Subject: [PATCH 1/3] test(ngClass): add the case mixed array/object variable with a mutating object --- test/ng/directive/ngClassSpec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index a50f611e4b18..3076fa418db0 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -409,6 +409,18 @@ describe('ngClass', function() { expect(e2.hasClass('even')).toBeTruthy(); expect(e2.hasClass('odd')).toBeFalsy(); })); + + it('should support changing multiple classes via variable array mixed with conditionally via a map', inject(function($rootScope, $compile) { + $rootScope.classVar = ['', {orange: true}]; + element = $compile('
')($rootScope); + $rootScope.$digest(); + + $rootScope.classVar[1].orange = false; + $rootScope.$digest(); + + expect(element.hasClass('orange')).toBeFalsy(); + })); + }); describe('ngClass animations', function() { From e54492c02e54c9520d6b599621f084eb5535abcd Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Sun, 10 Apr 2016 01:08:59 +0200 Subject: [PATCH 2/3] fix(ngClass): fix shallowCopy of mixed array and object --- src/ng/directive/ngClass.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); + } } } }; From 3b91bb1a440935f60f6c667ff728b85cff65b48a Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Sun, 10 Apr 2016 18:41:22 +0200 Subject: [PATCH 3/3] fix(ngClass): improve code of mutating object test case --- test/ng/directive/ngClassSpec.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 3076fa418db0..1d7cd1b56f16 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -410,16 +410,20 @@ describe('ngClass', function() { expect(e2.hasClass('odd')).toBeFalsy(); })); - it('should support changing multiple classes via variable array mixed with conditionally via a map', inject(function($rootScope, $compile) { - $rootScope.classVar = ['', {orange: true}]; - element = $compile('
')($rootScope); - $rootScope.$digest(); + it('should support mixed array/object variable with a mutating object', + inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); - $rootScope.classVar[1].orange = false; - $rootScope.$digest(); + $rootScope.classVar = [{orange: true}]; + $rootScope.$digest(); + expect(element).toHaveClass('orange'); - expect(element.hasClass('orange')).toBeFalsy(); - })); + $rootScope.classVar[0].orange = false; + $rootScope.$digest(); + + expect(element).not.toHaveClass('orange'); + }) + ); });