fix(common): ngStyle should ignore undefined values (#34422)
Prior to ivy, undefined values passed in an object to the ngStyle directive were ignored. Restore this behavior by ignoring keys that point to undefined values. closes #34310 PR Close #34422
This commit is contained in:

committed by
Kara Erickson

parent
05b4f8eb9d
commit
ee1eebd5d8
@ -157,6 +157,29 @@ import {ComponentFixture, TestBed, async} from '@angular/core/testing';
|
||||
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
|
||||
expectNativeEl(fixture).toHaveCssStyle({'font-size': '12px'});
|
||||
}));
|
||||
|
||||
it('should skip keys that are set to undefined values', async(() => {
|
||||
const template = `<div [ngStyle]="expr"></div>`;
|
||||
|
||||
fixture = createTestComponent(template);
|
||||
|
||||
getComponent().expr = {
|
||||
'border-top-color': undefined,
|
||||
'border-top-style': undefined,
|
||||
'border-color': 'red',
|
||||
'border-style': 'solid',
|
||||
'border-width': '1rem',
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expectNativeEl(fixture).toHaveCssStyle({
|
||||
'border-color': 'red',
|
||||
'border-style': 'solid',
|
||||
'border-width': '1rem',
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user