角度2:在静态解析符号值时遇到错误. -如何将其转换为工厂方法? [英] Angular 2 : Error encountered resolving symbol values statically. - How can I turn this into a factory method?
本文介绍了角度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?
推荐答案
严格按照建议进行操作:
Do exactly as it suggested:
// 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 ...
这篇关于角度2:在静态解析符号值时遇到错误. -如何将其转换为工厂方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文