Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Angular2 NGmodule中,我想根据条件加载2组不同的路由模块_Javascript_Angular_Typescript_Rxjs - Fatal编程技术网

Javascript 在Angular2 NGmodule中,我想根据条件加载2组不同的路由模块

Javascript 在Angular2 NGmodule中,我想根据条件加载2组不同的路由模块,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,在Angular2中,我想为求职者和雇主加载2套不同的路线模块1。URL相同,但求职者和雇主的模块不同。因此,我想根据登录会话动态加载路由模块。有什么方法可以做到吗??还是有更好的方法可以在angular2中实现 基本上,我希望能够加载基于条件的模块 下面是示例代码 @NgModule({ imports: [BrowserModule, HttpModule,customRoutes.getCustomRoutes(), SharedModule.forRoot()

在Angular2中,我想为求职者和雇主加载2套不同的路线模块1。URL相同,但求职者和雇主的模块不同。因此,我想根据登录会话动态加载路由模块。有什么方法可以做到吗??还是有更好的方法可以在angular2中实现

基本上,我希望能够加载基于条件的模块

下面是示例代码

@NgModule({
  imports: [BrowserModule, HttpModule,customRoutes.getCustomRoutes(),
            SharedModule.forRoot()],
  declarations: [AppComponent],
  providers: [
    {
    provide: APP_BASE_HREF,
    useValue: '<%= APP_BASE %>'  },
    CanActivateGuard,AccountService, ProfileService],
  bootstrap: [AppComponent]
})

export class AppModule {

  constructor(private _http:Http,@Inject(AccountService) authService:AccountService) {


  }
//但是getCustomRoutes需要是一个静态方法才能在NGModule中调用。但如果我将其设置为静态,我将获得对accountService对象的访问权


(是否有更好的方法实现基于用户会话加载不同路由的功能)

不幸的是,目前不支持在运行时配置路由。当角度应用程序被引导时,路径是指定的,但之后不能更改它们。

如果我想根据特定条件加载模块,这是可能的吗?如果设置了雇主会话,则我需要加载仅针对雇主的模块
export class customRoutes {

  public customRoutes;
  constructor(@Inject(AccountService)  accountService:AccountService) {


  }

 getCustomRoutes() {
    return this.customRoutes = (accountService.getCheckEmployer())?JobSeekerRoutes:EmployerRoutes;
  }

}