0

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

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.