gpt4 book ai didi

库模块中的 Angular APP_INITIALIZER 生成元数据编译时错误 : Lambda not supported

转载 作者:行者123 更新时间:2023-12-03 20:27:11 26 4
gpt4 key购买 nike

这是我的 ng 库模块代码

   @NgModule({
imports: [NgIdleModule.forRoot()],
providers: [ {
provide: APP_INITIALIZER,
useFactory: (idleStateChangeHandlerService: IdleStateChangeHandlerService) => () => console.log(IdleStateChangeHandlerService),
multi: true,
deps: [IdleStateChangeHandlerService]
}]
})
export class IdleActivityModule {
static forRoot(config: IdleActivityConfig): ModuleWithProviders {
return {
ngModule: IdleActivityModule,
providers: [
{
provide: IdleActivityConfigInjectionToken,
useValue: config
}
]
};
}
}

构建时:
> Compiling TypeScript sources through ngc ERROR:
> C:/_dev/seemis-workspace/projects/shared-modules/src/lib/idle-activity/idle-activity.module.ts:9:1:
> Error encountered in metadata generated for exported symbol
> 'IdleActivityModule':
> C:/_dev/seemis-workspace/projects/shared-modules/src/lib/idle-activity/idle-activity.module.ts:13:17:
> Metadata collected contains an error that will be reported at runtime:
> Lambda not supported. {"__symbolic":"error","message":"Lambda not
> supported","line":12,"character":16}

如果我搬家 APP_INITIALIZER将提供程序放入应用程序模块中,这很好,但我不希望应用程序必须具备这些知识。

最佳答案

这是用一些功夫黑魔法解决的:

使用@dynamic 添加代码注释

// @dynamic
@NgModule({ ...

Angular Compiler Options除了更加困惑之外,没有其他原因。

关于库模块中的 Angular APP_INITIALIZER 生成元数据编译时错误 : Lambda not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58852854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com