【Ionic】Argument of type“**Service”is not assignable to parameter of type 'RebirthHttp'.
程序员文章站
2022-05-19 10:50:17
...
一、现象描述
Argument of type“**Service”is not assignable to parameter of type ‘RebirthHttp’.Property’http’ is missing in type ‘DataService’;
二、解决办法
原因是**Service.ts没有继承RebirthHttp;
在原来的**Service.ts基础上继承RebirthHttp即可;
原来的**Service:
@Injectable()
export class DataService {
}
现在的**Service.ts:
@Injectable()
export class DataService extends RebirthHttp{
constructor(protected http: Http,
jsonp: Jsonp,
protected rebirthHttpProvider: RebirthHttpProvider,
@Inject(EnvVariables) public envVariables) {
super({ http, jsonp, rebirthHttpProvider });
}
这里,需要构造器构造Http,Jsonp,RebirthHttpProbider,并且注入EnvVariables;实现父类http,jsonp,rebirthHttpProvider;
这里的RebirthHttp接口如下(源代码):
//导包
import { Http, Jsonp, Request, RequestOptions, RequestOptionsArgs } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
//导出接口RebirthHttpInterceptor;
export interface RebirthHttpInterceptor {
request?: (option: RequestOptions) => RequestOptions | void;//请求
response?: (response: Observable<any>, request?: RequestOptions) => Observable<any> | void;
}
//导出声明类:RebirthHttpProvider;
export declare class RebirthHttpProvider {
private interceptors;//私有接口;
constructor();//构造器;
getInterceptors(): RebirthHttpInterceptor[];//获取接口;
addInterceptor(interceptor: RebirthHttpInterceptor): RebirthHttpProvider;//添加接口;
addRequestInterceptor(interceptor: (res: RequestOptions) => RequestOptions)://添加请求接口; RebirthHttpProvider;
addResponseInterceptor(interceptor: (res: any) => any): RebirthHttpProvider;//添加响应接口
addResponseErrorInterceptor(interceptor: (res: any) => any): RebirthHttpProvider;//添加错误响应接口;
handleRequest(req: RequestOptions): RequestOptions;//请求处理;
handleResponse(res: Observable<any>, request?: RequestOptions): Observable<any>;//响应处理;
baseUrl(host: string, excludes?: RegExp[]): RebirthHttpProvider;//基本Url;
headers(headers?: {}): RebirthHttpProvider;//头们
json(): RebirthHttpProvider;//json;
}
//导出声明类RebirthHttp;
export declare class RebirthHttp {
protected http: Http;
protected jsonp: Jsonp;
protected rebirthHttpProvider: RebirthHttpProvider;
constructor(option?: {
http?: Http;
jsonp?: Jsonp;
rebirthHttpProvider?: RebirthHttpProvider;
});
protected getBaseUrl(): string;
protected getDefaultHeaders(): Object;
protected requestInterceptor(req: RequestOptions): RequestOptions | void;
protected responseInterceptor(res: Observable<any>, request?: RequestOptions): Observable<any> | void;
}
//导出声明类RebirthHttpService服务;
export declare class RebirthHttpService {
private http;
private rebirthHttpProvider;
enableJson: boolean;
constructor(http: Http, rebirthHttpProvider: RebirthHttpProvider);
request<T>(url: string | Request, options?: RequestOptionsArgs): Observable<T>;
get<T>(url: string, options?: RequestOptionsArgs): Observable<T>;
post<T>(url: string, body: any, options?: RequestOptionsArgs): Observable<T>;
put<T>(url: string, body: any, options?: RequestOptionsArgs): Observable<T>;
delete<T>(url: string, options?: RequestOptionsArgs): Observable<T>;
patch<T>(url: string, body: any, options?: RequestOptionsArgs): Observable<T>;
head<T>(url: string, options?: RequestOptionsArgs): Observable<T>;
options<T>(url: string, options?: RequestOptionsArgs): Observable<T>;
protected requestInterceptor(req: RequestOptions): RequestOptions | void;
protected responseInterceptor(res: Observable<any>, request?: RequestOptions): Observable<any> | void;
private handleRequest<T>(requestOptions);
}
//导出声明方法:BaseUrl:
export declare function BaseUrl(url: string): <TFunction extends Function>(target: TFunction) => TFunction;
//导出声明方法:默认头儿们;
export declare function DefaultHeaders(headers: any): <TFunction extends Function>(target: TFunction) => TFunction;
//导出声明变量:Path;
export declare var Path: (key?: string) => (target: RebirthHttp, propertyKey: string | symbol, parameterIndex: number) => void;
//导出声明变量:Query;
export declare var Query: (key?: string) => (target: RebirthHttp, propertyKey: string | symbol, parameterIndex: number) => void;
//导出声明变量:Body;
export declare var Body: (target: RebirthHttp, propertyKey: string | symbol, parameterIndex: number) => void;
//导出声明变量:Header;
export declare var Header: (key?: string) => (target: RebirthHttp, propertyKey: string | symbol, parameterIndex: number) => void;
//导出声明方法:头儿们
export declare function Headers(headersDef: any): (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明方法:Produces
export declare function Produces(producesDef: string): (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const:GET
export declare const GET: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const:JSONP
export declare const JSONP: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const:POST
export declare const POST: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const:PUT
export declare const PUT: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const:DELETE
export declare const DELETE: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const:HEAD
export declare const HEAD: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
////导出声明const:PATCH
export declare const PATCH: (url: string) => (target: RebirthHttp, propertyKey: string, descriptor: any) => any;
//导出声明const REBIRTH_HTTP_PROVIDERS
export declare const REBIRTH_HTTP_PROVIDERS: Array<any>;
上一篇: 网鼎杯 2018 unfinish
下一篇: 2020网鼎杯玄武组移动安全wp