# Attach data\['\_body'\] value with variable to use it in another function

**URL:** <https://forum.ionicframework.com/t/attach-data-body-value-with-variable-to-use-it-in-another-function/126448>\
**Category:** ionic-v3\
**Created:** [March 30, 2018, 10:24pm UTC](https://forum.ionicframework.com/t/attach-data-body-value-with-variable-to-use-it-in-another-function/126448 "2018-03-30T22:24:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [March 30, 2018, 10:33pm UTC](https://forum.ionicframework.com/t/attach-data-body-value-with-variable-to-use-it-in-another-function/126448/2 "2018-03-30T22:33:56Z")

</div>

> [@lado](#):
>
> Advice would be helpful

- Everything up to the `post()` call can be done much more simply just using [`HttpParams`](https://angular.io/api/common/http/HttpParams), 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 with `HttpClient`. Split those two things up. If you absolutely have to modify state from inside of `function1()`, use the `tap` operator 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 `_body` property and should not be accessing it directly.
- `post` is generic, so declare an interface (let’s call it `Thingy`) and let `HttpClient` do the work.
- Always give every function you write a declared response type. `function1()`'s should be `Observable<Thingy>` or `Observable<SomethingGeneratedFromThingy>`.
- The operator you are looking for to chain asynchronous operations here is `mergeMap`.

---

_[View the full topic](https://forum.ionicframework.com/t/attach-data-body-value-with-variable-to-use-it-in-another-function/126448)._
