gpt4 book ai didi

angular - 如何在 Angular 6 中使用 http delete()

转载 作者:太空狗 更新时间:2023-10-29 17:42:44 25 4
gpt4 key购买 nike

我的服务.ts

  import { Injectable } from '@angular/core';
import { Http, Response,Headers,RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import 'rxjs/Rx';
import{Router} from'@angular/router';
import 'rxjs/add/operator/map';
@Injectable()
export class ManageJobDeleteService{
constructor(private http: Http,private router:Router){};
DeleteRequestToAPI(post_jobs_id:string){
let body = JSON.stringify({post_jobs_id:post_jobs_id});
let headers = new Headers({ 'Content-Type': 'application/json'});
let options = new RequestOptions({ headers: headers });
console.log(body);
console.log(options);
return this.http.delete('http://127.0.0.1:8000/api/employer/post_jobs/',body,options)//HERE I AM GETTING ERROR
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response){
let body = res.json();
console.log(body);
return body || [];
}
private handleError (error: any) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}

错误:

Expected 1-2 arguments, but got 3.ts(2554).

请告诉我如何在 Angular 6 中使用 http 删除请求传递正文和选项。

最佳答案

删除时没有正文参数。

因此,您需要删除 body 参数。

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>
}

编辑:如何传递 post_jobs_id?

你可以使用 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);

关于angular - 如何在 Angular 6 中使用 http delete(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53850009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com