Recover data

Hello,

I would have liked to know, how to retrieve a particular value only, here is my current code (the data name is “latdept”:

this.http.get('dddddddd?id=' + this.id, {}, {})
          .then(res => {
          console.log(res.data.latdept);
          this.post = JSON.parse(res.data);
          console.log('ici');
        })

You do not want to be manually calling JSON.parse here. You do want to be supplying a proper template parameter to get. Emulate the idioms in Tour of Heroes part 6 - the specific part I linked to deals with your exact situation.

Hello,

I looked at your link, I had a little trouble understanding, I’m still on it and trying to figure out the method used, but if you have a little example I’m interested

To make it simpler, I would like to retrieve a particular value from the same ts page.

Store the value in a variable to use it further down in my code

It’s right in the link I gave before:

Other APIs may bury the data that you want within an object. You might have to dig that data out by processing the Observable result with the RxJS map() operator.

Although not discussed here, there’s an example of map() in the getHeroNo404() method included in the sample source code.

So look at that method in stackblitz, or go through the most excellent RxJS decision tree, where you should end up at either map or pluck.