fix(elements): handle falsy initial value (#31604)

Fixes angular/angular#30834

PR Close #31604
This commit is contained in:
Balint Mero
2019-07-17 13:39:54 +02:00
committed by Miško Hevery
parent 376ad9c3cd
commit 7151eae36d
2 changed files with 47 additions and 10 deletions

View File

@ -125,12 +125,12 @@ export class ComponentNgElementStrategy implements NgElementStrategy {
* cached and set when the component is created.
*/
setInputValue(property: string, value: any): void {
if (strictEquals(value, this.getInputValue(property))) {
if (!this.componentRef) {
this.initialInputValues.set(property, value);
return;
}
if (!this.componentRef) {
this.initialInputValues.set(property, value);
if (strictEquals(value, this.getInputValue(property))) {
return;
}
@ -164,9 +164,8 @@ export class ComponentNgElementStrategy implements NgElementStrategy {
/** Set any stored initial inputs on the component's properties. */
protected initializeInputs(): void {
this.componentFactory.inputs.forEach(({propName}) => {
const initialValue = this.initialInputValues.get(propName);
if (initialValue) {
this.setInputValue(propName, initialValue);
if (this.initialInputValues.has(propName)) {
this.setInputValue(propName, this.initialInputValues.get(propName));
} else {
// Keep track of inputs that were not initialized in case we need to know this for
// calling ngOnChanges with SimpleChanges