【发布时间】:2017-12-01 11:16:36
【问题描述】:
我使用 Angular AOT 编译器版本 4.1.3
我有一个导出工厂方法的组件库,然后用于提供服务:
export function libServiceFactory(itemId: string) {
return (http: Http): LibService => {
return new LibService(http, itemId);
};
};
我用ngc成功编译库。
然后导入编译好的库,我在网站的AppModule中使用LibServiceFactory:
providers: [
{ provide: SERVICE_TOKEN, useFactory: libServiceFactory('foo'), deps: [Http] }
],
我使用ng build编译网站,我收到以下错误:
ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 5:10 in the
original .ts file), resolving symbol libServiceFactory in C:/Projects/MyProject/code/MyWebsite/node_modules/@mylibrary/service.factory.d.ts, res
olving symbol AppModule in C:/Projects/MyProject/code/MyWebsite/src/app/app.module.ts, resolving symbol AppModule in C:/Projects/MyProject/code/MyWebsite/src/app/app.mod
ule.ts, resolving symbol AppModule in C:/Projects/MyProject/code/MyWebsite/src/app/app.module.ts
错误(position 5:10 in the original .ts file)指向工厂方法中的匿名函数:return (http: Http): LibService => {
作为附加信息,我创建和使用工厂方法的方式与 official documentation regarding injection tokens 中建议的 Angular 相同。
我的错误是预期的行为吗?还是我的实现有问题?
【问题讨论】:
-
你找到解决办法了吗?
标签: angular angular-factory angular-aot angular-compiler