The http.delete(url, options)
确实接受一个身体。您只需将其放入选项对象中即可。
http.delete('/api/something', new RequestOptions({
headers: headers,
body: anyObject
}))
Reference options interface:
https://angular.io/api/http/RequestOptions https://angular.io/api/http/RequestOptions
UPDATE:
上面的代码片段仅适用于 Angular 2.x、4.x 和 5.x。
对于 6.x 及以上版本,Angular 提供 15 种不同的重载。在这里检查所有重载:https://angular.io/api/common/http/HttpClient#delete https://angular.io/api/common/http/HttpClient#delete
使用示例:
const options = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
}),
body: {
id: 1,
name: 'test',
},
};
this.httpClient
.delete('http://localhost:8080/something', options)
.subscribe((s) => {
console.log(s);
});