I've been trying to create an @NgModule (named ModelsModule) made of objects like User, Book, Library, Movie, and so on. Doing this I'm trying to not to import every object every time I need it but importing them at the beginning in the AppModule (main @NgModule) and use them as many times I want.
Objects/Entities/Classes... example
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,
Book,
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,
SettingsDialog
],
providers: [
// ModelsModule (?)
],
imports: [
BrowserModule,
HttpModule,
// ModelsModule (?)
MaterialModule.forRoot()
],
bootstrap: [AppComponent]
})
export class AppModule { }