RPPATEL
RPPATEL

Reputation: 25

how to pass header and body together in angular

In angular how to pass header and body together in one put request,

     const httpOptions = {
      headers: new HttpHeaders({
        'Authorization': this.login.token
      }),
      body: {'fiToDelete': id}
    };
     return this.httpClient.put('https://admin.chatomate.dev.gradlesol.com/app/fi/delete', httpOptions).subscribe();

this method is not working ...

Upvotes: 1

Views: 816

Answers (1)

ABGR
ABGR

Reputation: 5235

You just have to remove the body part from the options and put it separately as the second argument inside the request.

const httpOptions = {
  headers: new HttpHeaders({
    'Authorization': this.login.token
  }),
 
};
 return this.http.put(url,  body: {'fiToDelete': id}, httpOptions).subscribe();

Another note, it seems you're trying to delete with a Put request. You might like to change it to a DELETE request.

Upvotes: 1

Related Questions