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

feat(ngClass): support multiple classes in key #7140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/ngClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function classDirective(name, selector) {
var classes = [], i = 0;
forEach(classVal, function(v, k) {
if (v) {
classes.push(k);
classes = classes.concat(k.split(' '));
}
});
return classes;
Expand Down
17 changes: 17 additions & 0 deletions test/ng/directive/ngClassSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ describe('ngClass', function() {
expect(e2.hasClass('odd')).toBeTruthy();
}));

it('should allow ngClass with overlapping classes', inject(function($rootScope, $compile, $animate) {
element = $compile('<div ng-class="{\'same yes\': test, \'same no\': !test}"></div>')($rootScope);
$rootScope.$digest();

expect(element).toHaveClass('same');
expect(element).not.toHaveClass('yes');
expect(element).toHaveClass('no');

$rootScope.$apply(function() {
$rootScope.test = true;
});

expect(element).toHaveClass('same');
expect(element).toHaveClass('yes');
expect(element).not.toHaveClass('no');
}));

it('should allow both ngClass and ngClassOdd/Even with multiple classes', inject(function($rootScope, $compile) {
element = $compile('<ul>' +
'<li ng-repeat="i in [0,1]" ng-class="[\'A\', \'B\']" ' +
Expand Down