angularrxjsbehaviorsubject

Behaviour subject inside the form group (as control)


I have a form group named currentForm with a form array named items. Due to applications component's issues I need to have a subject inside the item form group and I'm not sure if it's good practice.

let item = this.fb.group({
      myListAsSubject: [new BehaviorSubject<any[]>([])]
    });

Is this a safe solution? What should I watch out for?


Solution

  • Using behavior subject is not a common practice. There can be some issues which arise from it. Such as complexity which makes your code hard to understand . Another example is where you need to patch values of myListAsSubject, it would not be able to update the value as a form control and would require additional logic