It seems like the child component only gets set the first time the Observable emits.
Container component (map operator added for debugging):
this.form$ = this.createOrderStore.pipe(select(getFormGroup)).pipe(
tap((val) => {
console.log('observable emitted');
console.log(val);
return val;
})
);
Child component:
private _form: FormGroup;
@Input()
set form(val) {
console.log('set form');
if (val) {
this._form = val;
}
}
get form() {
return this._form;
}
Container template:
<app-order-form [form]="form$ | async"></app-order-form>
The first time the observable emits, console shows 'observable emitted', val is undefined, then 'set form'. However, since this first value is undefined, we don't set it in the template yet.
The second time the observable emits, console logs 'observable emitted', val is a complete form group (so it should trigger change detection), but 'set form' is not logged. This second value is the one I actually need to set in the template.
Is there a reason why the child component property is only set the first time the observable emits?
undefined === undefined, so it won't enter the set function? try logging it in the observable (btw, for logging you can usetap, no need to return anything from that)filterto theform$obs:.pipe(filter((form) => !!form)). Still doesn't explain it though