fix(elements): correctly handle setting inputs to undefined
(#36140)
Previously, when an input property was initially set to `undefined` it would not be correctly recognized as a change (and trigger `ngOnChanges()`). This commit ensures that explicitly setting an input to `undefined` is correctly handled the same as setting the property to any other value. This aligns the behavior of Angular custom elements with that of the corresponding components when used directly (not as custom elements). PR Close #36140
This commit is contained in:

committed by
Misko Hevery

parent
b14ac96750
commit
9ba46d9f88
@ -94,6 +94,7 @@ describe('ComponentFactoryNgElementStrategy', () => {
|
||||
it('should call ngOnChanges with the change', () => {
|
||||
expectSimpleChanges(componentRef.instance.simpleChanges[0], {
|
||||
fooFoo: new SimpleChange(undefined, 'fooFoo-1', true),
|
||||
falsyUndefined: new SimpleChange(undefined, undefined, true),
|
||||
falsyNull: new SimpleChange(undefined, null, true),
|
||||
falsyEmpty: new SimpleChange(undefined, '', true),
|
||||
falsyFalse: new SimpleChange(undefined, false, true),
|
||||
@ -104,11 +105,13 @@ describe('ComponentFactoryNgElementStrategy', () => {
|
||||
it('should call ngOnChanges with proper firstChange value', fakeAsync(() => {
|
||||
strategy.setInputValue('fooFoo', 'fooFoo-2');
|
||||
strategy.setInputValue('barBar', 'barBar-1');
|
||||
strategy.setInputValue('falsyUndefined', 'notanymore');
|
||||
tick(16); // scheduler waits 16ms if RAF is unavailable
|
||||
(strategy as any).detectChanges();
|
||||
expectSimpleChanges(componentRef.instance.simpleChanges[1], {
|
||||
fooFoo: new SimpleChange('fooFoo-1', 'fooFoo-2', false),
|
||||
barBar: new SimpleChange(undefined, 'barBar-1', true),
|
||||
falsyUndefined: new SimpleChange(undefined, 'notanymore', false),
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
Reference in New Issue
Block a user