How to use http delete () in Angular 6
What about defining your post_jobs_id
in your url? And after that get the id
in your backend.
For example, you can define :
DeleteRequestToAPI(post_jobs_id:string) {
const url = `http://127.0.0.1:8000/api/employer/post_jobs/${post_jobs_id}`;
return this.http.delete(url, {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
})
.map(this.extractData)
.catch(this.handleError);
}
there is no body argument on delete.
so, you need to remove body argument.
this.http.delete('http://127.0.0.1:8000/api/employer/post_jobs/',options)
Reference
class HttpClient {
delete(url: string,
options: { headers?: HttpHeaders | { [header: string]: string | string[]; };
observe?: HttpObserve; params... = {}): Observable<any>
}
Edit: How can I pass post_jobs_id?
you can use HttpParams:
let httpParams = new HttpParams().set('aaa', '111');
httpParams.set('bbb', '222');
let options = { params: httpParams };
this.http.delete('http://127.0.0.1:8000/api/employer/post_jobs/',options);