在我的 Angular 应用程序中,我试图在我的模块中使用工厂提供程序:
export function getMyFactory(): () => Window {
return () => window;
}
@NgModule({
providers: [
{ provide: WindowRef, useFactory: getMyFactory() },
],
})
export class MyModule {}
Run Code Online (Sandbox Code Playgroud)
但这失败了:
在为导出的符号“MyModule”生成的元数据中遇到错误:
收集的元数据包含运行时会报错:Lambda not supported
typescript angular-providers angular-factory angular angular-dependency-injection
我使用 Angular AOT 编译器版本 4.1.3
我有一个组件库,它导出一个工厂方法,然后用于提供服务:
export function libServiceFactory(itemId: string) {
return (http: Http): LibService => {
return new LibService(http, itemId);
};
};
Run Code Online (Sandbox Code Playgroud)
我编译库与ngc
成功。
然后导入编译好的库,我LibServiceFactory
在网站的 AppModule 中使用:
providers: [
{ provide: SERVICE_TOKEN, useFactory: libServiceFactory('foo'), deps: [Http] }
],
Run Code Online (Sandbox Code Playgroud)
我编译网站,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 …
Run Code Online (Sandbox Code Playgroud)