In my project, I sometimes want to update the available options in a list when the user changes the selected value in another list. To do this, I've used valueChanges
with the pipe
operator and switchMap
like this:
this.form.controls.typeControl.valueChanges
.pipe(
switchMap((typeId: number) => {
return this.typesService.getProjectsByType(typeId);
}),
)
.subscribe((projects) => {
//...
});
Now I have the problem that I need to perform two http requests at once to update multiple lists instead of just one. When I try to add a second switchMap
, I get error TS2345: Argument of type 'OperatorFunction<number, Project[]>' is not assignable to parameter of type 'OperatorFunction<any, number>'.
Here is how I tried to do this:
this.form.controls.typeControl.valueChanges
.pipe(
switchMap((typeId: number) => {
return this.typesService.getProjectsByType(typeId);
}),
switchMap((typeId: number) => {
return this.typesService.getProgramsByType(typeId);
}),
)
.subscribe(([projects, programs]) => {
//...
});
How can I add a second http request here so I can process the data received by both request in the subscribe
?