ConnectionBackend
升级到2.0.0-rc.5
后, TypeProvider 2.0.0
不再有效。
当我把它放在我的提供者列表中时。我从Visual Studio代码中得到了这个错误。
[ts]类型' {bootstrap:typeof AppComponent [];声明:( typeof LoginComponent | typeof EmailLoginCompo ...'不能分配给' NgModule'类型的参数。 财产类型及提供者'是不相容的。 键入'(任何[] |类型的HttpModule | typeof位置|类型AuthStore | typeof RequestInterceptor | typ ...'不能分配给类型'(TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider |任何[])[]&#39 ;. 输入' any [] | typeof HttpModule | typeof位置| typeof AuthStore | typeof RequestInterceptor |键入...'不能分配类型' TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider |任何[]&#39 ;. 输入' typeof ConnectionBackend'不能分配类型' TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider |任何[]&#39 ;. 输入' typeof ConnectionBackend'不能分配给任何[]'类型。 物业'推动'在类型' typeof ConnectionBackend'。
中缺少
我查看了changelog,但我看不到任何适用的内容。我注意到,例如HTTP_PROVIDERS
已替换为HttpModule
,但这是在更改日志中,并且缺少整个引用。这很奇怪。
我想在角度2的发布版本中使用什么来提供XHRBackend?
这是所有相关代码的附录。问题部分已经完成:
这是我的NGModule。我的应用运行正常(除了需要提供Http对象时断开),注释掉ConnectionBackend
行。
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
LoginComponent,
EmailLoginComponent,
EmailLoginCodeComponent,
ErrorComponent,
ExampleComponent,
],
imports: [
BrowserModule,
routing,
],
providers: [
appRoutingProviders,
HttpModule,
Location,
AuthStore,
RequestInterceptor,
ResponseInterceptor,
ConnectionBackend, // THIS IS THE PROBLEM LINE
{
provide: Config,
deps: [XHRBackend, RequestOptions],
useFactory: (
backend: XHRBackend,
defaultOptions: RequestOptions
) => {
let config = new Config(new Http(backend, defaultOptions));
// I hope this promise finishes
let promise: Promise<Config> = config.load().then( response => config);
return config;
},
},
{
provide: PanelGuidStore,
useFactory: (
() =>
new PanelGuidStore()
),
},
Locator,
{
provide: AuthService,
// Factory for AuthService
// use standard http here to avoid circular references
// (as well as pointless attempts to put Auth tokens inside Auth requests)
deps: [XHRBackend, RequestOptions, AuthStore, Config, Locator, PanelGuidStore],
useFactory: (
backend: XHRBackend,
defaultOptions: RequestOptions,
authStore: AuthStore,
config: Config,
locator: Locator,
panelGuidStore: PanelGuidStore
) =>
new AuthService(
new Http(backend, defaultOptions), authStore, config, locator, panelGuidStore
),
},
{
provide: Http,
// Factory for Http
// Use custom http provider to inject access tokens and deal with access token expiry
deps: [XHRBackend, RequestOptions, Location, RequestInterceptor, ResponseInterceptor],
useFactory: (
backend: XHRBackend,
defaultOptions: RequestOptions,
location: Location,
requestInterceptor: RequestInterceptor,
responseInterceptor: ResponseInterceptor,
authService: AuthService) =>
new AuthHttpProvider(
backend, defaultOptions, requestInterceptor, responseInterceptor
),
},
],
})
这就是视觉工作室代码所说的关于它的提供商&#34;参数:
(property)providers :( any [] | typeof HttpModule | typeof Location | typeof AuthStore | typeof RequestInterceptor | typeof ResponseInterceptor | { [x:number]:未定义; 提供:typeof Config; deps :( typeof XHRBackend | typeof RequestOptions)[]; useFactory :(后端:XHRBackend,defaultOptions:RequestOptions)=&gt;配置; } | { [x:number]:未定义; 提供:typeof PanelGuidStore; useFactory :()=&gt; PanelGuidStore; } | typeof Locator | { [x:number]:未定义; 提供:typeof AuthService; deps :( typeof XHRBackend | typeof RequestOptions | typeof AuthStore | typeof Config | typeof Locator | typeof PanelGuidStore)[]; useFactory :(后端:XHRBackend,defaultOptions:RequestOptions,authStore:AuthStore,config:Config,locator:Locator,panelGuidStore:PanelGuidStore)=&gt; AuthService; } | { [x:number]:未定义; 提供:typeof Http; deps :( typeof XHRBackend | typeof RequestOptions | typeof Location | typeof RequestInterceptor | typeof ResponseInterceptor)[]; useFactory :(后端:XHRBackend,defaultOptions:RequestOptions,location:Location,requestInterceptor:RequestInterceptor,responseInterceptor:ResponseInterceptor,authService:AuthService)=&gt; AuthHttpProvider; })[]
答案 0 :(得分:2)
ConnectionBackend
只是一个界面。这是XHRBackend
实现的接口。因此,您可以取出ConnectionBackend
提供商。
您收到丢失的HRBackend
错误的原因是您应该导入 HttpModule
,而不是将其添加为提供商
imports: [ HttpModule /* DO */ ],
providers: [ HttpModule /* DONT */ ]