在HomeModule中导入RouterModule时,应该在SharedModule导出时通过SharedModule导入

时间:2018-01-17 03:56:43

标签: angular angular-ui-router

import { ModuleWithProviders, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HomeComponent } from './home.component';
import { SharedModule } from '../shared'; 
const homeRouting: ModuleWithProviders = RouterModule.forChild([
  {
    path: '',
    component: HomeComponent
  } 
]);
@NgModule({
    imports: [
       homeRouting,
      SharedModule
 ],
    declarations: [
       HomeComponent
 ],
    providers: []
 })
export class HomeModule {}


import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
@NgModule({
    imports: [
      CommonModule,
      FormsModule,
      ReactiveFormsModule,
      HttpModule,
      RouterModule
  ],
    declarations: [],
    exports: [
       CommonModule,
       FormsModule,
       ReactiveFormsModule,
       HttpModule,
       RouterModule
  ]
})
export class SharedModule {}

SharedModule已经导出了RouterModule和HomeModule导入的SharedModule,那么RouterModule应该是不可用的,那么为什么在HomeModule中明确导入了RouterModule?

1 个答案:

答案 0 :(得分:0)

RouterModule.forChild()内,导入AppModule。 在RouterModule.forRoot(...)内,导入forRoot

静态string selectedAdmin = Session["Admin"].ToString(); 方法允许使用Root注入器注册路由器服务。它是路由工作所必需的模块,因为它将路由器服务注册为单例,并使整个应用程序中的路由可用。