Include an own module in another Angular 5

0

My question is: How can I import modules from Angular material in my own module, and then import that module in app.module.ts?.

This is my personal module:

import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatMenuModule } from '@angular/material/menu';
import { MatButtonModule } from '@angular/material/button';

@NgModule({
    imports: [
        BrowserAnimationsModule,
        MatMenuModule,
        MatButtonModule
    ],
    declarations: [

    ]
})

export class MaterialModule { }

whereupon what I do is the following in app.module.ts:

import {MaterialModule} from './material.module';

imports array:

imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    MaterialModule
  ],

The fact is that I get errors, but if I do it directly everything in app.module.ts works for me. I do not want to have everything imported in the same module, so as not to make it difficult when reviewing, or correcting code. Thanks in advance, greetings.

    
asked by H. Díaz 25.04.2018 в 14:35
source

1 answer

1

You must export the modules also so they can be used in different modules, you just have to add an array with the property to your NgModule.

import { NgModule } from '@angular/core';
import { MatMenuModule } from '@angular/material/menu';
import { MatButtonModule } from '@angular/material/button';

@NgModule({
    imports: [
        MatMenuModule,
        MatButtonModule
    ],
    declarations: [

    ],
    exports:[
        MatMenuModule,
        MatButtonModule
    ]
})
export class MaterialModule { }
    
answered by 25.04.2018 в 16:50