R
R
Rudy Dudy2019-08-22 12:51:53
Angular
Rudy Dudy, 2019-08-22 12:51:53

Merge several observables - how to find out which observable worked?

Hello.
There are several forms that merge into one stream. The task is to find out which form has been changed ( valueChanges ) and depending on which form the user has changed - you need to make a request with certain parameters.

merge(observable1, observable2, observable3, observable4).pipe(
map(()=> {
observable1 changes? ok, change some parameter 
observable2 changes? ok then change other parameter. 
observable4 soo changes only this observable? ok, then set parameter
return this.someService(parameter)
})
).subscribe(response => { do something else})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2019-08-22
@search

In this case, it would be reasonable to do the necessary actions for each of the observables separately.

merge(
  observable1.pipe(
    // do stuff related to form 1
  ),
  observable2.pipe(
    // do stuff related to form 2
  ),
  ...
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question