在我的 Angular 应用程序中,我尝试使用 factory provider在我的模块中:
export function getMyFactory(): () => Window {
return () => window;
}
@NgModule({
providers: [
{ provide: WindowRef, useFactory: getMyFactory() },
],
})
export class MyModule {}
但这失败了:Error encountered in metadata generated for exported symbol 'MyModule':
Metadata collected contains an error that will be reported at runtime: Lambda not supported
最佳答案
我在 GitHub 的一个线程上发现了一个简单的解决方案:Arrow lambda not supported in static function发表者haochi
解决方案基本上是:
assigning the result to a variable, then return the variable
因此,就我而言,我通过替换解决了:
export function getMyFactory(): () => Window {
return () => window;
}
和:
export function getMyFactory(): () => Window {
const res = () => window;
return res;
}
关于Angular:收集的元数据包含将在运行时报告的错误:不支持 Lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57594723/