【Ionic】Argument of type“**Service”is not assignable to parameter of type 'RebirthHttp'.

一、现象描述

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;//基本Urlheaders(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);
}
//导出声明方法:BaseUrlexport 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>;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陶洲川

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值