Search code examples
angularrxjsangular-formlysubject

Don't receive data from Subject.next()


I have an angular application using ngx-formly(dynamic forms) with a formly type (select) in which I have a subscribe(). In the component the formly form is defined with an Observable for the formly type and created dynamically.

In the component I have a Subject and buttons, producing a next(), the formly type does not receive the data (also didn't receive a complete). A subscribe() in the component itself works.

Changing from Subject to BehaviorSubject<number>() I receive one time data in the formly type, but no further data on next().

The code is meant to be used in a stepper/wizard, changing to a next step, all select's in this step should reload their options.

A 100% working stackblitz example can be found here: https://stackblitz.com/edit/angular-9ts63k?file=src%2Fapp%2Fapp.component.ts

I have a good understanding of rxjs (using rxjs and ngx-store for two years; I am by far an expert), but with this I am completely stuck, so any ideas why rxjs with the same setup as in the stackblitz example is not working in my application are welcome.

  • "@angular/core": "^6.1.9"
  • "rxjs": "^6.3.3"
  • no rxjs-compat

Solution

  • I found the culprit. The application makes use of dynamic forms and used cloneDeep in a service to copy the formly field definition (which was overlooked). Up till now the application used only a return of an Observable without using a Subject which worked. Now using an additional Subject things didn't work anymore, inspecting the Observable stream showed that one was closed.