- We will create a separate component that deals with importing and exporting of Material Component.
Let generate a new module using below command :
ng g m material
material.module.ts
import { NgModule } from '@angular/core'; import { MatButtonModule} from '@angular/material'; const MaterialComponent = [ MatButtonModule, ]; @NgModule({ imports: [ MaterialComponent ], exports: [ MaterialComponent ] }) export class MaterialModule { }
app,module.ts
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MaterialModule } from './material/material.module'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MaterialModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
app.component.ts
<button mat-raised-button>Hello World</button>
Output :