在 angular 15.2 中有自动脚本将您的应用程序迁移到独立结构,它记录在这里https://github.com/angular/angular/blob/main/packages/core/schematics/ng-generate/standalone-migration /README.md
但运行它实际上并没有迁移
main.server.ts
或 app.server.module.ts
文件
在导入中用
AppModule
替换 AppComponent
时使应用程序编译但在缺少提供程序的运行时失败
例如
NullInjectorError: No provider for InjectionToken angularfire2.app.options
失踪
provideFirebaseApp(() => initializeApp(environment.firebase)),
即使我将所有这些提供程序复制到 AppServerModule,我仍然得到
error NG6009: The `AppComponent` class is a standalone component, which can not be used in the `@NgModule.bootstrap` array. Use the `bootstrapApplication` function for bootstrap instead.
没有前进的道路
您需要致电
bootstrapApplication
:
看起来像:
bootstrapApplication(AppComponent, {
providers: [
importProvidersFrom(RouterModule.forRoot(AppRoutes),
BrowserModule.withServerTransition({ appId: 'serverApp' }))
]
})