Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 74eb468

Browse files
drpicoxgkalpak
authored andcommitted
fix(ngClass): fix watching of an array expression containing an object
Closes #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

+5-1
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

+16
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)