Angular 2:静态解析符号值时遇到错误.- 我怎样才能把它变成工厂方法? [英] Angular 2 : Error encountered resolving symbol values statically. - How can I turn this into a factory method?
本文介绍了Angular 2:静态解析符号值时遇到错误.- 我怎样才能把它变成工厂方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
安装 Angular-cli 后出现此错误:
After installing Angular-cli I am getting this error:
Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a refer
ence to an exported function (position 55:19 in the original .ts file), resolving symbol AppModule in C:/TM-2013/Debt/Debt Platform/Code/main/Think.Debt.Presentation/deb-explorer-with-angular
-cli/src/app/app.module.ts
在我的 App.Module.ts 中它不喜欢这段代码:
In my App.Module.ts it does not like this section of code:
供应商:[
// These are needed throughout the site
AppConfigService,
{ provide: APP_INITIALIZER, useFactory: configServiceFactory, deps: [AppConfigService], multi: true },
{
provide: HttpService,
useFactory: (backend: XHRBackend, options: RequestOptions) => {
return new HttpService(backend, options);
},
deps: [XHRBackend, RequestOptions]
}
]、
使用 .load
{ provide: APP_INITIALIZER, useFactory: (config: AppConfigService) => () => config.load(), deps: [AppConfigService], multi: true },
{
provide: HttpService,
useFactory: (backend: XHRBackend, options: RequestOptions) => {
return new HttpService(backend, options);
},
deps: [XHRBackend, RequestOptions]
}
是否可以将其转换为工厂类,因为它不喜欢当前的用法?
Is it possible to turn this into a factory class as it does not like this current usage?
推荐答案
完全按照建议去做:
// named exported function
export function httpFactory(backend: XHRBackend, options: RequestOptions) {
return new HttpService(backend, options);
}
export function configServiceFactory(config: AppConfigService) {
return () => config.load();
}
// after goes declaration of you module with `providers`
// ... skipped ...
{ provide: APP_INITIALIZER, useFactory: configServiceFactory, deps: [AppConfigService], multi: true },
{
provide: HttpService,
useFactory: httpFactory, // reference to the function
deps: [XHRBackend, RequestOptions]
}
// ... skipped ...
这篇关于Angular 2:静态解析符号值时遇到错误.- 我怎样才能把它变成工厂方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文