My current strategy involves storing the form values in my ngrx store so that users can easily navigate around the site and return to the form if needed. The concept is to have the form values repopulate from the store using an observable.
This is how I am currently implementing it:
constructor(private store: Store<AppState>, private fb: FormBuilder) {
this.images = images;
this.recipe$ = store.select(recipeBuilderSelector);
this.recipe$.subscribe(recipe => this.recipe = recipe); // console.log() => undefined
this.recipeForm = fb.group({
foodName: [this.recipe.name], // also tried with an OR: ( this.recipe.name || '')
description: [this.recipe.description]
})
}
The store receives an initial value, which seems to be correctly passing through my selector function. However, by the time the form is being created, it appears that the value has not returned yet. As a result, this.recipe
remains undefined.
Is this approach incorrect, or is there a way to ensure that the observable is returned before creating the form?