[this question is based on https://ngrx-forms.readthedocs.io/]
I've an array of topics(strings) inside my angular component. I'm using ngrx-store to manage state along with ngrx-forms for managing forms. During the initialization of the component, I dispatch some actions for each topic inside the component.
ngOnInit(): void {
this.formState$ = this.store.pipe(select(s => s.filterByTopics.formState))
this.topicsOptions$ = this.store.pipe(select(s => s.filterByTopics.topicsOptions))
Object.keys(this.topics).forEach(topic => this.store.dispatch(new CreateTopicControlAction(topic)))
}
That works fine and the ngrx-form controls are getting added.
But the real issue is that if I again visit the same component again it reinitializes the actions (since ngOnInit contains all the actions) and spits out an error:
Uncaught Error: Group 'filterByTopicsForm.topics' already has child control '0'!
How can I prevent this?
Is there any other workaround?