Doubts with non-angular post method

0

Hello, I'm trying to do a POST method that returns me a 'User' object.

In my BackEnd I have the following code:

 //Add um Usuarios
 public Usuarios Post([FromBody]Usuarios usuario)
 {
     return _usuariosServices.Adicionar(usuario);
 }

That is, I get a 'User' object.

In the angle I call this method and the request arrives in the BackEnd, but I can not play the return on an angle variable ...

My Angular method is as follows ...

CriandoUsuario(usuario: UsuariosModel){
  let headers = new Headers();
  headers.append('Content-Type', 'application/json')

  this.http.post('${API}' + 'Usuarios'
  , JSON.stringify(usuario)
  , { headers: headers })
  . subscribe(() => {});
 }

So I understand, it is necessary to do something inside the 'Subscribe', but I do not know what this something is ... Thanks in advance ...

    
asked by anonymous 05.05.2018 / 23:32

1 answer

1

You are complicating it unnecessarily. Then you give the subscribe on the return function.

httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'      
})

constructor(private httpClient: HttpClient) {         
}


criarUsuario(usuario: UsuariosModel){
  return this.httpClient.post('${API}Usuarios', user, this.httpOptions)
}
    
07.05.2018 / 10:59