Skip to content

Commit 7d49443

Browse files
vicbmhevery
authored andcommitted
fix(common): A null value should remove the style on IE (#21679)
fixes #21064 PR Close #21679
1 parent 86d9612 commit 7d49443

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/common/src/directives/ng_style.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export class NgStyle implements DoCheck {
6565
const [name, unit] = nameAndUnit.split('.');
6666
value = value != null && unit ? `${value}${unit}` : value;
6767

68-
this._renderer.setStyle(this._ngEl.nativeElement, name, value as string);
68+
if (value != null) {
69+
this._renderer.setStyle(this._ngEl.nativeElement, name, value as string);
70+
} else {
71+
this._renderer.removeStyle(this._ngEl.nativeElement, name);
72+
}
6973
}
7074
}

packages/common/test/directives/ng_style_spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ import {ComponentFixture, TestBed, async} from '@angular/core/testing';
6161
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
6262
}));
6363

64+
// https://github.com/angular/angular/issues/21064
65+
it('should add and remove styles which names are not dash-cased', async(() => {
66+
fixture = createTestComponent(`<div [ngStyle]="{'color': expr}"></div>`);
67+
68+
getComponent().expr = 'green';
69+
fixture.detectChanges();
70+
expectNativeEl(fixture).toHaveCssStyle({'color': 'green'});
71+
72+
getComponent().expr = null;
73+
fixture.detectChanges();
74+
expectNativeEl(fixture).not.toHaveCssStyle('color');
75+
}));
76+
6477
it('should update styles using style.unit notation when unit changes', async(() => {
6578
const template = `<div [ngStyle]="expr"></div>`;
6679

0 commit comments

Comments
 (0)