Skip to content

Commit 74eb468

Browse files
drpicoxgkalpak
authored andcommitted
fix(ngClass): fix watching of an array expression containing an object
Closes angular#14405
1 parent d088fbe commit 74eb468

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ng/directive/ngClass.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function classDirective(name, selector) {
7878
updateClasses(oldClasses, newClasses);
7979
}
8080
}
81-
oldVal = shallowCopy(newVal);
81+
if (isArray(newVal)) {
82+
oldVal = newVal.map(function(v) { return shallowCopy(v); });
83+
} else {
84+
oldVal = shallowCopy(newVal);
85+
}
8286
}
8387
}
8488
};

test/ng/directive/ngClassSpec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,22 @@ describe('ngClass', function() {
409409
expect(e2.hasClass('even')).toBeTruthy();
410410
expect(e2.hasClass('odd')).toBeFalsy();
411411
}));
412+
413+
it('should support mixed array/object variable with a mutating object',
414+
inject(function($rootScope, $compile) {
415+
element = $compile('<div ng-class="classVar"></div>')($rootScope);
416+
417+
$rootScope.classVar = [{orange: true}];
418+
$rootScope.$digest();
419+
expect(element).toHaveClass('orange');
420+
421+
$rootScope.classVar[0].orange = false;
422+
$rootScope.$digest();
423+
424+
expect(element).not.toHaveClass('orange');
425+
})
426+
);
427+
412428
});
413429

414430
describe('ngClass animations', function() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy