gpt4 book ai didi

javascript - ionic 2 rc0 : create a custom http service

转载 作者:太空宇宙 更新时间:2023-11-04 16:31:25 25 4
gpt4 key购买 nike

我正在从 ES6 项目 (beta11) 转移到带有 rc0 的新项目,并且在重写我的自定义 http 服务时遇到一些问题。

在我的providers/文件夹中,我有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: 未捕获( promise 中):错误:./CheckAccess 类 CheckAccess_Host 中出现错误 - 内联模板:0:0 导致:没有 ConnectionBackend 提供程序!

我不知道我做错了什么。有人可以帮忙吗?

最佳答案

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

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

关于javascript - ionic 2 rc0 : create a custom http service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39775876/

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