角度 15 如果我使用独立结构,main.server.ts 应该是什么样子

问题描述 投票:0回答:1

在 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.

没有前进的道路

angular server-side-rendering angular-universal
1个回答
0
投票

您需要致电

bootstrapApplication

看起来像:

bootstrapApplication(AppComponent, {
  providers: [
     importProvidersFrom(RouterModule.forRoot(AppRoutes), 
     BrowserModule.withServerTransition({ appId: 'serverApp' }))
  ]
})
© www.soinside.com 2019 - 2024. All rights reserved.