我有一个应该在应用程序启动时运行的库。
我看到 Angular 19 现在使用provideAppInitializer。我确实使用了自动角度ng update
迁移 cli,它更改了代码。
// From
{
provide: APP_INITIALIZER,
useFactory: (service: NgxBackButtonService) => () => service,
deps: [NgxBackButtonService],
multi: true,
},
// To
provideAppInitializer(() => {
const initializerFn = ((service: NgxBackButtonService) => () => service)(inject(NgxBackButtonService))
return initializerFn()
}
但这不起作用并抛出以下错误
Argument of type '() => NgxBackButtonService' is not assignable to parameter of type '() => void | Observable<unknown> | Promise<unknown>'.
Type 'NgxBackButtonService' is not assignable to type 'void | Observable<unknown> | Promise<unknown>'.ts(2345)
有人知道我该如何适应它吗?