diff --git a/packages/common/src/directives/ng_style.ts b/packages/common/src/directives/ng_style.ts index 988cee4419..d048f9774d 100644 --- a/packages/common/src/directives/ng_style.ts +++ b/packages/common/src/directives/ng_style.ts @@ -65,6 +65,10 @@ export class NgStyle implements DoCheck { const [name, unit] = nameAndUnit.split('.'); value = value != null && unit ? `${value}${unit}` : value; - this._renderer.setStyle(this._ngEl.nativeElement, name, value as string); + if (value != null) { + this._renderer.setStyle(this._ngEl.nativeElement, name, value as string); + } else { + this._renderer.removeStyle(this._ngEl.nativeElement, name); + } } } diff --git a/packages/common/test/directives/ng_style_spec.ts b/packages/common/test/directives/ng_style_spec.ts index baddb55144..0c494c7f42 100644 --- a/packages/common/test/directives/ng_style_spec.ts +++ b/packages/common/test/directives/ng_style_spec.ts @@ -61,6 +61,19 @@ import {ComponentFixture, TestBed, async} from '@angular/core/testing'; expectNativeEl(fixture).not.toHaveCssStyle('max-width'); })); + // https://github.com/angular/angular/issues/21064 + it('should add and remove styles which names are not dash-cased', async(() => { + fixture = createTestComponent(`
`); + + getComponent().expr = 'green'; + fixture.detectChanges(); + expectNativeEl(fixture).toHaveCssStyle({'color': 'green'}); + + getComponent().expr = null; + fixture.detectChanges(); + expectNativeEl(fixture).not.toHaveCssStyle('color'); + })); + it('should update styles using style.unit notation when unit changes', async(() => { const template = `
`;