angular – 类型’标题’没有与’RequestOptionsArgs’类型相同
发布时间:2020-12-17 07:55:21 所属栏目:安全 来源:网络整理
导读:我刚刚对Angular 4应用程序和构建工具进行了两次重要的升级: @ angular / core ^ 4.1.3 = ^ 4.2.4(和/ http,/ forms等) tslint ^ 5.3.2 = ^ 5.4.3 我有一个服务,声明这样的选项: @Injectable()export class WorkOrderService { private headers: Headers =
我刚刚对Angular 4应用程序和构建工具进行了两次重要的升级:
> @ angular / core ^ 4.1.3 => ^ 4.2.4(和/ http,/ forms等) 我有一个服务,声明这样的选项: @Injectable() export class WorkOrderService { private headers: Headers = new Headers({ 'Content-Type': 'application/json' }); private options: RequestOptions = new RequestOptions(this.headers); constructor(private http: Http) {} /* Methods ... */ } 以上现在不再验证tslint,抛出以下错误:
源(@ angular / http interface.d.ts:43)显然允许Headers作为RequestOptionsArgs: /** * Interface for options to construct a RequestOptions,based on * [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec. * * @experimental */ export interface RequestOptionsArgs { url?: string | null; method?: string | RequestMethod | null; /** @deprecated from 4.0.0. Use params instead. */ search?: string | URLSearchParams | { [key: string]: any | any[]; } | null; params?: string | URLSearchParams | { [key: string]: any | any[]; } | null; headers?: Headers | null; body?: any; withCredentials?: boolean | null; responseType?: ResponseContentType | null; }
4.3 HttpClient的更新
在角度4.3中引入的与 import { HttpClient,HttpHeaders } from "@angular/common/http"; private _options = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; 不再有RequestOptions:使用新的immutable Pre 4.3 / Http 我刚刚注意到RequestOptions现在要求您将命名选项显式传递为对象,如: headers: Headers = new Headers({ 'Content-Type': 'application/json' }); options: RequestOptions = new RequestOptions({ headers: this.headers }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容