Angular 4.0 http put request

后端 未结 3 935
天命终不由人
天命终不由人 2021-01-07 14:13

I\'ve written a function to send a http put request to update some data but it says, that it is not recieving any data:

updateHuman(human: Human) {
    const         


        
3条回答
  •  广开言路
    2021-01-07 15:00

    Observables are lazy, you need to be subscribed to them for them to work and retrieve anything. Did you subscribe to your method? Example:

    methodToUpdateHuman(human): void{
    ...
    this.updateHuman(human).subscribe((response) => {
       //do something with the response
       console.log.("Response is: ", response);
    },
    (error) => {
       //catch the error
       console.error("An error occurred, ", error);
    });
    }
    

    I suggest you read through the Angular Tour Of Heroses, it's based in angular 2 and most of the functionality is functional in angular 4, there is a section dedicated to http requests: https://angular.io/tutorial/toh-pt6

提交回复
热议问题