- Everything up to the
post()call can be done much more simply just usingHttpParams, with the added benefit that you don’t have to manually stringify anything - If this code is in a provider, you almost never want to be typing
subscribe. If it’s in a page, you never want to be directly interacting withHttpClient. Split those two things up. If you absolutely have to modify state from inside offunction1(), use thetapoperator to do it. I’m going to assume for the rest of this discussion that we’re writing a provider. - Don’t use the console or
JSON.stringify()to poke around in the internals of things. Read their public API documentation. - Therefore, you should never know of the existence of a
_bodyproperty and should not be accessing it directly. postis generic, so declare an interface (let’s call itThingy) and letHttpClientdo the work.- Always give every function you write a declared response type.
function1()'s should beObservable<Thingy>orObservable<SomethingGeneratedFromThingy>. - The operator you are looking for to chain asynchronous operations here is
mergeMap.
1 Like