gpt4 book ai didi

angular - 如何在 Angular2 编译器/cli ngc 命令中使用 RouterModule.forRoot()

转载 作者:太空狗 更新时间:2023-10-29 17:37:04 25 4
gpt4 key购买 nike

假设我有以下 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

我试着把它放在一个导出的常量中:

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"

等等

最佳答案

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

关于angular - 如何在 Angular2 编译器/cli ngc 命令中使用 RouterModule.forRoot(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41463860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com