How to make a massive delete in angular 4 with an array of ids

情到浓时终转凉″ 提交于 2021-02-20 04:08:05

问题


I'm trying to make a massive delete, in order to do that I have an Array<number> of the ids I want to delete. I can't pass this array as a parameter to the method this._httpService.delete(uri,options). The type of _httpService is Http.

So I'm looping the array and inside the loop I'm making single calls, but each call is async and I have certain logic to run when the loop ends.


回答1:


Actually you can send the id array in the body of a DELETE request, according to this answer, like so:

http.delete('/api/something', new RequestOptions({
    headers: headers,
    body: anyObject    // this would contain your ids
}))

So instead of issuing hundreds of requests, have your app make just one with all ids in the body.



来源:https://stackoverflow.com/questions/50892416/how-to-make-a-massive-delete-in-angular-4-with-an-array-of-ids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!