不應該在根級別導入全局可用(對於全局來說,我指的是所有子模塊和組件)?具有根級別導入的Angular2應用程序模塊
我有以下根/應用模塊:
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,
FormsModule,
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,
FormsModule,
dashboardRouting,
MdCoreModule,
MdButtonModule,
MdCardModule,
MdListModule,
MdSidenavModule,
MdToolbarModule,
MdIconModule,
],
declarations: [
DashboardComponent,
ActionsDialogComponent
],
providers: [
]
})
export class DashboardModule {}
爲什麼必須在材料模塊上,如果他們再次在根級別已經導入了礦石進口?
您的模塊應該是可重用的。爲什麼需要使用你的模塊的人將各種模塊導入他的根模塊?這隻會讓你的模塊難以重用。 –
O等等......這是真的。謝謝。 –