Sarkhan
Sarkhan

Reputation: 1289

DELETE method in typescript

I have this method. When I click on remove button it shows console.log-message but does not hit the server. What am I missing?

removeSelecteds(instances: number[]) : Observable<void>{

  var obj = { instanceIds: instances };

  console.log('JSON.stringify(obj)='+JSON.stringify(obj));

  return this.http
    .request(URLS.instances+'/remove', RequestMethod.Delete, JSON.stringify(obj))
    .map(res => {
      this.getInstances();
    }
  );
}

Thanks in advance

Upvotes: 0

Views: 2009

Answers (2)

You need to subscribe to your request observable

this.http
      .request(URLS.instances+'/remove', RequestMethod.Delete, JSON.stringify(obj))
      .map(res => {
          this.getInstances();
        }
      ).subscribe((result) => {
          console.log(result); //Output the result from the server
});

Edit: Since Angular 5 you dont need to .map() the request

Upvotes: 3

hagner
hagner

Reputation: 1050

You need to subscribe to a observable to "activate" it:

removeSelecteds(numbers).subscribe(res => console.log(res));

You can read more about angular http client and observables here: https://angular.io/guide/http

Upvotes: 0

Related Questions