-2

i have use http.get and http.post and i get a response from them but when i try http.put there is no result ( "return this.http.put(this.apiUpdate, data, httpOptions) " the problem is here i dont know why it doesn't excute it; however it works on backend and i have test it ,

enter code here

 apiUpdate: '*********/*****/update';

   public update-client(data: Client) {
   console.log("client: ",data);
  const httpOptions = {
    headers: new HttpHeaders({
    'Content-Type': 'application/json'
  })
     };

    // let options = new HttpRequestOptions({ headers: headers });


   console.log("service");
     return this.http.put(this.apiUpdate, data, httpOptions);
  }
  • 1
    Possible duplicate of [Angular 2 http.post() is not sending the request](https://stackoverflow.com/questions/36208732/angular-2-http-post-is-not-sending-the-request) – jonrsharpe Apr 29 '19 at 15:19

1 Answers1

0

This request is an observable, meaning that it'll need to be "kicked off" before it'll do anything. To do this you'll need to subscribe to the observable, this can be done using

this.http.put(this.apiUpdate, data, httpOptions).subscribe(result => {  ...  }); 

Doing this allows you to take the result from the post request and do whatever you wish within the {}. You are also able to catch errors too.

More info should be able to be found here: https://angular.io/tutorial/toh-pt6

  • i have already done , i have subscribe it on my page .ts updateAccount() { console.log("pressed"); this.data = { id: this.idClient, firstname: Firstname, lastname: Lastname, nbcnss: Nbcnss }; this.clientServiceProvider.updateClient(this.data).subscribe((res:any) => { console.log("puttt"); console.log(res); this.navCtrl.setRoot(HomePage); }, – Houssem Azzouz Apr 29 '19 at 15:19