How to add a body to Angular HttpClient delete function

前端 未结 3 1186
孤独总比滥情好
孤独总比滥情好 2021-01-01 08:46

Our project is migrating to Angular4, and use @angular/common/http Httpclient as the default network tool. But I found there are no body p

3条回答
  •  余生分开走
    2021-01-01 09:03

    I also get this problem and my solution is creating a new HttpRequest of delete method, then clone 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);
    });

    The clone() is required, because the body still can not be directly set in the new HttpRequest().

提交回复
热议问题