Skip to content

Commit 4a42669

Browse files
pkozlowski-opensourcealxhub
authored andcommitted
fix(common): properly take className changes into account (#21937)
Fixes #21932 PR Close #21937
1 parent 5c8340a commit 4a42669

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/common/src/directives/ng_class.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class NgClass implements DoCheck {
126126
(<any>rawClassVal).forEach((klass: string) => this._toggleClass(klass, !isCleanup));
127127
} else {
128128
Object.keys(rawClassVal).forEach(klass => {
129-
if (rawClassVal[klass] != null) this._toggleClass(klass, !isCleanup);
129+
this._toggleClass(klass, isCleanup ? false : !!rawClassVal[klass]);
130130
});
131131
}
132132
}

packages/common/test/directives/ng_class_spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ import {ComponentFixture, TestBed, async} from '@angular/core/testing';
290290
detectChangesAndExpectClassName(`init foo`);
291291
}));
292292

293+
it('should co-operate with the interpolated class attribute when interpolation changes',
294+
async(() => {
295+
fixture = createTestComponent(
296+
`<div [ngClass]="{large: false, small: true}" class="{{strExpr}}"></div>`);
297+
298+
detectChangesAndExpectClassName(`foo small`);
299+
300+
getComponent().strExpr = 'bar';
301+
detectChangesAndExpectClassName(`bar small`);
302+
}));
303+
293304
it('should co-operate with the class attribute and binding to it', async(() => {
294305
fixture =
295306
createTestComponent(`<div [ngClass]="objExpr" class="init" [class]="'foo'"></div>`);

0 commit comments

Comments
 (0)