typescript - Add Models/Entities/Objects to NgModule in Angular 2 -


i've been trying create @ngmodule (named modelsmodule) made of objects user, book, library, movie, , on. doing i'm trying not import every object every time need importing them @ beginning in appmodule (main @ngmodule) , use them many times want.

objects/entities/classes... example

export class author {   constructor (     public name: string,     public avatar: string   ) { } } 

modelsmodule

import { ngmodule } '@angular/core'; import { commonmodule } '@angular/common'; import { formsmodule } '@angular/forms';  import { author } './author/author.model'; (...)  @ngmodule({   imports: [     commonmodule,     formsmodule,     author,     book,     movie,     store   ], }) export class modelsmodule {} 

appmodule

import { browsermodule } '@angular/platform-browser'; import { ngmodule } '@angular/core'; import { formsmodule } '@angular/forms'; import { httpmodule } '@angular/http'; import { materialmodule } '@angular/material';  import { appcomponent, settingsdialog } './app.component';  // 1 import { modelsmodule } '../models/models.module';  @ngmodule({   declarations: [     appcomponent,     settingsdialog   ],   entrycomponents: [     appcomponent,     settingsdialog   ],   providers: [     // modelsmodule (?)   ],   imports: [     browsermodule,     httpmodule,     // modelsmodule (?)     materialmodule.forroot()   ],   bootstrap: [appcomponent] }) export class appmodule { } 

model classes have no place in angular. import class file need it, use it.

import { mymodel } './my.model';  class somecomponent {   model = new mymodel(); } 

it seems lot of newbies confused import statement in class, , think can somehow rid of them importing class angular somehow. not case. importing class file nothing specific angular. file imports way able use items 1 file in another.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -