我一直在尝试创建一个由 User、Book、Library、Movie 等对象组成的 @NgModule(名为ModelsModule )。这样做我试图不要在每次需要时都导入每个对象,而是在 AppModule (main @NgModule) 的开头导入它们并尽可能多次使用它们。
对象/实体/类...示例
export class Author {
constructor (
public name: string,
public avatar: string
) { }
}
型号模块
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,
Book,
Movie,
Store
],
})
export class ModelsModule {}
应用模块
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,
SettingsDialog
],
providers: [
// ModelsModule (?)
],
imports: [
BrowserModule,
HttpModule,
// ModelsModule (?)
MaterialModule.forRoot()
],
bootstrap: [AppComponent]
})
export class AppModule { }