diff --git a/packages/core/src/render3/instructions/styling.ts b/packages/core/src/render3/instructions/styling.ts index 1acf61c58a..f306c51c70 100644 --- a/packages/core/src/render3/instructions/styling.ts +++ b/packages/core/src/render3/instructions/styling.ts @@ -585,7 +585,7 @@ function resolveStylePropValue( if (value === NO_CHANGE) return value; let resolvedValue: string|null = null; - if (value !== null) { + if (isStylingValueDefined(value)) { if (suffix) { // when a suffix is applied then it will bypass // sanitization entirely (b/c a new string is created) diff --git a/packages/core/test/acceptance/styling_spec.ts b/packages/core/test/acceptance/styling_spec.ts index a2ce244bf2..f2a8d44dc8 100644 --- a/packages/core/test/acceptance/styling_spec.ts +++ b/packages/core/test/acceptance/styling_spec.ts @@ -2310,6 +2310,34 @@ describe('styling', () => { expect(fixture.debugElement.nativeElement.innerHTML).toContain('three'); }); + it('should allow to reset style property value defined using [style.prop.px] binding', () => { + @Component({ + template: '
', + }) + class MyComp { + left = ''; + } + + TestBed.configureTestingModule({declarations: [MyComp]}); + const fixture = TestBed.createComponent(MyComp); + fixture.detectChanges(); + + const checks = [ + ['15', '15px'], + [undefined, ''], + [null, ''], + ['', ''], + ['0', '0px'], + ]; + const div = fixture.nativeElement.querySelector('div'); + checks.forEach((check: any[]) => { + const [fieldValue, expectedValue] = check; + fixture.componentInstance.left = fieldValue; + fixture.detectChanges(); + expect(div.style.left).toBe(expectedValue); + }); + }); + onlyInIvy('only ivy treats [class] in concert with other class bindings') .it('should retain classes added externally', () => { @Component({template: `
`})