根本级别的导入不应该全局可用(全局我指的是所有子模块和组件)?
我有以下root / app模块:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule,ApplicationRef } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { HttpModule } from '@angular/http'; import { RouterModule } from '@angular/router'; import { appRouterProviders,routing } from './app.routes'; import { DashboardModule } from './dashboard/dashboard.module'; import { DecisionModule } from './decision/decision.module'; import { MdCoreModule } from '@angular2-material/core'; import { MdButtonModule } from '@angular2-material/button'; import { MdCardModule } from '@angular2-material/card'; import { MdListModule } from '@angular2-material/list'; import { MdSidenavModule } from '@angular2-material/sidenav'; import { MdToolbarModule } from '@angular2-material/toolbar'; import { MdIconModule } from '@angular2-material/icon'; @NgModule({ declarations: [ AppComponent ],imports: [ BrowserModule,CommonModule,FormsModule,HttpModule,RouterModule,routing,DashboardModule,MdCoreModule,MdButtonModule,MdCardModule,MdListModule,MdSidenavModule,MdToolbarModule,MdIconModule ],providers: [ appRouterProviders ],entryComponents: [ AppComponent ],bootstrap: [ AppComponent ] }) export class AppModule { }
如果我尝试在我的子模块中使用它们不显示的材质元素,这就是子模块的样子:
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { dashboardRouting } from './dashboard.routes'; import { DashboardComponent } from './dashboard.component'; import { ActionsDialogComponent } from './actions-dialog'; @NgModule({ imports: [ CommonModule,dashboardRouting,],declarations: [ DashboardComponent,ActionsDialogComponent ],providers: [ ] }) export class DashboardModule {}
但是,如果我导入它们显示的子模块中的材料模块.这是材料设计组件工作时子模块的样子:
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { dashboardRouting } from './dashboard.routes'; import { DashboardComponent } from './dashboard.component'; import { ActionsDialogComponent } from './actions-dialog'; import { MdCoreModule } from '@angular2-material/core'; import { MdButtonModule } from '@angular2-material/button'; import { MdCardModule } from '@angular2-material/card'; import { MdListModule } from '@angular2-material/list'; import { MdSidenavModule } from '@angular2-material/sidenav'; import { MdToolbarModule } from '@angular2-material/toolbar'; import { MdIconModule } from '@angular2-material/icon'; @NgModule({ imports: [ CommonModule,MdIconModule,providers: [ ] }) export class DashboardModule {}
如果材料模块已经在根级别导入,为什么必须再次在子级别上导入材料模块?