5

假设我有以下 appRoutingModule:

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

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

使用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

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

export const routerModule =  RouterModule.forRoot( routes );

但这会给出这个错误:

Error: Error encountered resolving symbol values statically

什么是解决方法/解决方法来让它工作?如果我无法将路由传递给 RouterModule,如何定义路由?

我正在使用版本:

"@angular/compiler": "~2.4.0",
"@angular/compiler-cli": "~2.4.0",
"@angular/platform-server": "~2.4.0",
"@angular/router": "~3.4.0"

等等

4

2 回答 2

2

我通过将 angular 恢复到版本 2.3.1 解决了这个问题。看起来它在 2.4.0 版本中被破坏了..

于 2017-01-05T08:18:52.867 回答
1

为什么您的代码既不导入 BrowserModule 也不导入 CommonModule?你试过这个吗?

@NgModule( { imports: [BrowserModule, ApplicationsModule, RouterModule.forRoot( [ { path: '', component: ApplicationlistComponent }]) ], declarations: [ApplicationlistComponent], bootstrap: [ApplicationlistComponent] } ) export class AppRoutingModule { } 要尝试的另一件事是将路由器的代码放在单独的文件中,例如 app.routing.ts:

const routes: Routes = path: '',
    component: ApplicationlistComponent

export const routing = RouterModule.forRoot(routes);

在@NgModule 中:

@NgModule( {
  imports: [BrowserModule, ApplicationsModule, 
           routing
],
  declarations: [ApplicationlistComponent],
于 2017-01-04T12:56:25.217 回答