5
사용자, 도서, 라이브러리, 영화 등과 같은 객체로 구성된 @NgModule (모델명 ModelsModule)을 만들려고했습니다. 이렇게 할 때마다 필요한 모든 개체를 가져 오지 않고 처음에 AppModule (main @NgModule)으로 가져 와서 원하는만큼 여러 번 사용하도록 노력하고 있습니다.각도 2의 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,
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 { }
이것은 좋은 연습이며, 실제로 각도 CLI가 어떻게 물건을 구성하는지 보여줍니다. 문제/질문은 무엇입니까? – Meir
간단한 클래스를 ngModule로 가져올 수 없습니다. – MatWaligora