2016-09-29 47 views
1

我正在从一个ES6项目(beta11)转移到一个新的项目与rc0,我有一些问题,以重写我的自定义http服务。Ionic 2 rc0:创建一个自定义http服务

在我的供应商/文件夹,我有customhttp.ts:

import {Injectable } from "@angular/core"; 
import {Http, Headers} from "@angular/http"; 
import {RequestOptions, XHRBackend} from '@angular/http'; 
@Injectable() 

export class CustomHttp extends Http { 
    constructor(xhrBackend: XHRBackend, requestOptions: RequestOptions) { 
    super(xhrBackend, requestOptions); 
    } 
    //some other methods, which override the defaults from Http 
} 
在我app.mmdule.ts

我有进口这一点,并在页面我添加为供应商

import {CustomHttp} from '../providers/customhttp'; 
... 

@NgModule({ 
    ... 
    providers: [CustomHttp] 
}) 

想要使用它

import {CustomHttp } from '../../providers/customhttp'; 
export class CheckAccess { 
    constructor(private customHttp: CustomHttp) 
} 

的.TS编译但浏览器输出

error_handler.js:45EXCEPTION:未捕获(承诺中):错误:./CheckAccess类中的错误CheckAccess_Host - 内联模板:0:0由于以下原因而导致:没有为ConnectionBackend提供程序!

我找不到我做错了什么。谁能帮忙?

+0

问题是带班** ** ConnectionBackend。将此课程添加到提供者,您应该会很好! – Shmarkus

回答

1

导入XHRBackend和您的应用程序模块中RequestOptions并通过以下设置为供应商检查:

providers :[ 
{ 
    provide: CustomHttp, 
    useFactory: (backend: XHRBackend, defaultOptions: RequestOptions) => { 
    return new CustomHttp(backend, defaultOptions); 
    }, 
    deps: [ XHRBackend, RequestOptions] 
    } 
] 
+0

嗨!我试过了,但问题仍然存在: - /仍然找不到提供ConnectionBackend –

+0

我有同样的问题,这解决了它! – Gabriel