1

im trying to add Angular Material to my Angular project but always getting this particular error.

Here is the error on VSC Terminal

I've already added

import {MatDialogModule} from '@angular/material/dialog'

@NgModule({
  declarations: [
   ...
  ],
  imports: [
   ...
   MatDialogModule

into my app.module.ts

And here i am wondering what did i do wrong when every time i tried importing the material module, the error says all other module is not found

9
  • share your package.json Commented Jun 6, 2018 at 5:41
  • codeshare.io/29VZ74 here, i already tried npm install @angular/material --save , or adding dependencies manually to package json. Edited because i pressed enter prematurely Commented Jun 6, 2018 at 5:48
  • I can't access your link kindly update your question with your package.json Commented Jun 6, 2018 at 5:50
  • 1
    Mate if your angular version is 5 then use the same material version see this They have provided a working stackblitz check out the dependency section and adjust your package.json accordinly else if your angular version is 6 check this and do the same Commented Jun 6, 2018 at 6:35
  • 1
    You can install specific version of material npm install --save @angular/[email protected] and npm install --save @angular/[email protected] Commented Jun 6, 2018 at 8:32

2 Answers 2

1

you need to install material module npm install --save @angular/material @angular/cdk then declare in your app.module.ts file like below

import {MatDialogModule} from "@angular/material";

@NgModule({
    declarations: [
        ...
        CourseDialogComponent
    ],
    imports: [
        ...
        MatDialogModule
    ],
    providers: [
       ...
    ],
    bootstrap: [AppComponent],
    entryComponents: [CourseDialogComponent]
})
export class AppModule {
}
Sign up to request clarification or add additional context in comments.

4 Comments

I already done that. Im sorry i didnt put enough information to my question
Turns out when i tried to npm install --save @angular/material , the npm shows npm WARN @angular/[email protected] requires a peer of @angular/core@>=6.0.0-beta.0 <7.0.0 but none is installed. You must install peer dependencies yourself.. Does this mean i need to update my angular version to v.6? Is there a way i install the material module to match my current Angular version, since im afraid if i update my Angular version some of my code is not working
which version you use for angular?
1

Alright it seems @Vikas has answered my question in the comment section. Turns out when im installing my material module through npm it automatically trying to install the latest version of the material module. In my case it didnt work because im still using angular 5 when the npm trying to install angular material v6^. Hence why this warning appears in the terminal after im trying to install it through npm >> npm WARN @angular/[email protected] requires a peer of @angular/core@>=6.0.0-beta.0 <7.0.0 but none is installed. You must install peer dependencies yourself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.