Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在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 {
}

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

等等

@H_618_24@
我通过将角度恢复到2.3.1版本来解决这个问题. 看起来它在2.4.0版本中被打破了..

大佬总结

以上是大佬教程为你收集整理的如何在Angular2 compiler / cli ngc命令中使用RouterModule.forRoot()全部内容,希望文章能够帮你解决如何在Angular2 compiler / cli ngc命令中使用RouterModule.forRoot()所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。