Reputation: 1289
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
Reputation: 423
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
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