How to add body to Angular HttpClient removal function

Our project migrates to Angular4 and uses @angular/common/http Httpclient as the default network tool. But I found that there are no body parameters in the delete function. How to add a body to remove a function? Thank you

+5
source share
2 answers

Instead, you can use the generic request method for the HttpClient class. This method has a body in options. https://angular.io/api/common/http/HttpClient#members

for example this.http.request('delete', 'url', { body: ... })

+11
source

I also get this problem, and my solution creates a new HttpRequest method to delete, then clones this request, reset its body with your data.

 let req = new HttpRequest('DELETE', 'url'); let newReq = req.clone({body: [10]}); this.http.request(newReq).subscribe((res) => { console.log(res); }, (err) => { console.log(err); }); 

clone() required because the body is still impossible to set directly in new HttpRequest() .

+1
source

Source: https://habr.com/ru/post/1271520/


All Articles