consecutive rest API http calls angular 4 -


i looked answers here found none go ahead , try explain situation can in hope one.

here situation : building angular 4 spa consumes rest api backend. in 1 of component have fetch several sets of data backend (from different methods), , need have these different sets of data display chart in component.

if make consecutive http calls in init method , call process_data method, angular not wait http responses before calls processing method. method called when needed data not there yet, can cause errors.

the solution have right : fix implemented time being following :

  • i make first http request, subscribe.
  • in subscription make second http request, subscribe
  • and on each subsequent http request
  • in last .subscribe() call processing method.

the result being big init method quite hard read/debug because of nested http requests. fix works ugly , hard reuse, serious issue since developing company. brings me the...

question : there better (cleaner/standard/good practice) way of achieving same result ?

tl;dr : there way of making several consecutive http requests , wait completed (and wait response) before proceeding ?

notes : though developing spa company, intern (thus, still @ school, still learning ropes). in addition not being real engineer yet new angular , web development in general.of course, apologize if answer question obvious.

secondly, english not native language apologize english-related mistakes in post.

i thank in advance answers.

i believe find looking in flatmaps or other solutions found in great tutorial.

flatmaps make multiple http requests linear.

to quote official documentation:

transform items emitted observable observables, flatten emissions single observable


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -