Sending a POST and how do I retrieve the data on the ANGLE?

-1
onSubmit() {
console.log(this.formulario.value)

this.http.post(this.configUrl, (this.formulario.value)).pipe(
 map(res => res))
.subscribe(dados => console.log(dados))   
}

This is my post code, I am sending a message to the server and it returns me a JSON, how would I retrieve this so I can insert it on my screen?

    
asked by anonymous 28.10.2018 / 22:45

1 answer

0

Good morning Fernando, the POST method of http is to write the data only, you only get the code related to his status (success, error or others). To retrieve the data you have recorded and displayed on the screen, you must make another request, but this time with the GET method.

It would look like this:

At your service:

recuperaDados() {
  return this.http.get(this.getURL);  
}

In your component, you can do with ASYNC PIPE, or just by subscribing to the return:

this.servico.recuperaDados().subscribe(val => console.log(val));

This way you only need to save to a local variable that has access to the template (HTML).

I hope I have helped, try to take a look at the documentation in the part of Dependency Injection, follow the link link

    
29.10.2018 / 15:28