小编Pie*_*t K的帖子

如何在Angular2 compiler/cli ngc命令中使用RouterModule.forRoot()

假设我有以下appRoutingModule:

export const routes: Route[] = [
  {
    path: '',
    component: ApplicationlistComponent
  }
];

@NgModule( {
  imports: [ ApplicationsModule, RouterModule.forRoot( routes ) ],
  exports: [ RouterModule ],
  declarations: [ApplicationlistComponent]
} )
export class AppRoutingModule {
}
Run Code Online (Sandbox Code Playgroud)

使用ngc cli命令编译时,会出现以下错误:

Error: Error encountered resolving symbol values statically. Calling function 'RouterModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppRoutingModule in C:/git/mxt-frontend/landing-page-client/src/client/app/app-routing.module.ts, resolving symbol AppRoutingModule in C:/git/mxt-frontend/landing-page-client/src/client/app/app-routing.module.ts
Run Code Online (Sandbox Code Playgroud)

我尝试将它放在导出的const中:

export const …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular2-compiler angular

5
推荐指数
1
解决办法
3956
查看次数