Reputation: 261
I just wonder how to implement http delete in Ionic2(Angular2). I do have an JSON API and I simply wanted to delete a specific data in it.
I wanted to delte this data:
this.http.delete('http://sample.com/XXX/api.php/cart?filter=cart.customer_id,eq,21&transform=1
I know that it is just a basic question but I have no idea how to implement. Hope you guys can help me. Thank you in advance.
Upvotes: 0
Views: 2314
Reputation: 1439
Here is the link to angular 2 http here (which is what Ionic 2 uses)
It will look something like this:
delete() : Observable<any> {
return this.http.delete(http://sample.com/XXX/api.php/cart?filter=cart.customer_id,eq,21&transform=1)
}
then you can use it else where like so:
this.service.delete().subscribe(()=>{
//do something after deleted
})
On the PHP side you will need to grab the variables:
$req = $_GET['filter']
Upvotes: 0
Reputation: 31895
First of all, you have to make sure you have the permission to execute DELETE on the URL.
Secondly, make sure your url is correct:
http://sample.com/XXX/api.php/cart?filter=cart.customer_id,eq,21&transform=1
Finally, the delete command for Http
is
delete(url: string, options?: RequestOptionsArgs): Observable<Response>
it returns Observable
which means it wouldn't be execute until you invoke subscribe()
on it:
this.http.delete(YOUR_URL).subscribe(
resp => console.log('deleted'),
error => console.log('error occur, delete fail')
);
Upvotes: 1