can not find module “@angular/material”

前端 未结 7 883
余生分开走
余生分开走 2021-01-31 02:47

I\'m using Angular 2. When I\'m trying to import \"@angular/material\" i\'m getting error for this. I\'m importing packages like:

import {MdDialog} from \"@angul         


        
7条回答
  •  忘了有多久
    2021-01-31 03:14

    Follow these steps to begin using Angular Material.

    Step 1: Install Angular Material

    npm install --save @angular/material
    

    Step 2: Animations

    Some Material components depend on the Angular animations module in order to be able to do more advanced transitions. If you want these animations to work in your app, you have to install the @angular/animations module and include the BrowserAnimationsModule in your app.

    npm install --save @angular/animations
    

    Then

    import {BrowserAnimationsModule} from '@angular/platform browser/animations';
    
    @NgModule({
    ...
      imports: [BrowserAnimationsModule],
    ...
    })
    export class PizzaPartyAppModule { }
    

    Step 3: Import the component modules

    Import the NgModule for each component you want to use:

    import {MdButtonModule, MdCheckboxModule} from '@angular/material';
    
    @NgModule({
    ...
    imports: [MdButtonModule, MdCheckboxModule],
    ...
     })
     export class PizzaPartyAppModule { }
    

    be sure to import the Angular Material modules after Angular's BrowserModule, as the import order matters for NgModules

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';
    import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
    
    import {MdCardModule} from '@angular/material';
    @NgModule({
        declarations: [
            AppComponent,
            HeaderComponent,
            HomeComponent
        ],
        imports: [
            BrowserModule,
            FormsModule,
            HttpModule,
            MdCardModule
        ],
        providers: [],
        bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    Step 4: Include a theme

    Including a theme is required to apply all of the core and theme styles to your application.

    To get started with a prebuilt theme, include the following in your app's index.html:

    
    

提交回复
热议问题