Body of Http.DELETE request in Angular2

前端 未结 12 1982
旧巷少年郎
旧巷少年郎 2020-12-02 08:23

I\'m trying to talk to a somewhat RESTful API from an Angular 2 frontend.

To remove some item from a collection, I need to send some other data in addition to the re

12条回答
  •  萌比男神i
    2020-12-02 09:20

    Below is a relevant code example for Angular 4/5 with the new HttpClient.

    import { HttpClient } from '@angular/common/http';
    import { HttpHeaders } from '@angular/common/http';
    
    public removeItem(item) {
        let options = {
          headers: new HttpHeaders({
            'Content-Type': 'application/json',
          }),
          body: item,
        };
    
        return this._http
          .delete('/api/menu-items', options)
          .map((response: Response) => response)
          .toPromise()
          .catch(this.handleError);
      }
    

提交回复
热议问题