My plan is to store the values of a form in my ngrx store to allow my users to navigate around the site and back to the form if they wish. The idea would be that the values of the form would repopulate from the store using an observable.
here is how I'm doing it currently:
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 is given an initial value which I have seen passes through my selector function properly, but by the time my form is created, I don't think that value has returned. Therefore this.recipe is still undefined.
Is this the wrong approach, or can I somehow ensure that the observable is returned before creating the form?