How to add a body to Angular HttpClient delete function

前端 未结 3 1182
孤独总比滥情好
孤独总比滥情好 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:14

    const httpOptions = {
        headers: new HttpHeaders({ 'Content-Type': 'application/json' }), body: your body data
    };
    
    
    return new Promise(resolve => {
        this.httpClient.delete(URL, httpOptions)       
                       .subscribe(res => {     
                           resolve(res);
                       }, err => {               
                           resolve(err);
                       });
        });
    

    by using httpOptions, you can set header and body in it. please refer this https://angular.io/tutorial/toh-pt6#delete-a-hero

提交回复
热议问题