我一直在尝试创建一个由User,Book,Library,Movie等对象组成的@NgModule(名为ModelsModule).这样做我试图不在每次需要时导入每个对象,而是在AppModule(主@NgModule)的开头导入它们并使用它们多次我想要的.
对象/实体/类……示例
export class Author { constructor ( public name: string,public avatar: string ) { } }
ModelsModule
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { Author } from './author/author.model'; (...) @NgModule({ imports: [ CommonModule,FormsModule,Author,Movie,Store ],}) export class ModelsModule {}
的AppModule
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { MaterialModule } from '@angular/material'; import { AppComponent,SettingsDialog } from './app.component'; // THAT ONE import { ModelsModule } from '../models/models.module'; @NgModule({ declarations: [ AppComponent,SettingsDialog ],entryComponents: [ AppComponent,providers: [ // ModelsModule (?) ],imports: [ BrowserModule,HttpModule,// ModelsModule (?) MaterialModule.forRoot() ],bootstrap: [AppComponent] }) export class AppModule { }