Link to home
Start Free TrialLog in
Avatar of Anthony Horner
Anthony Horner

asked on

Angular - adding a material.module.ts to build

I would like to add the Material Design Components to my angular 9 project to make my life a bit easier.

I added it to my application and then got the following as an error for some existing code (when I realised I had to install @angular/material)


    ERROR in src/app/app.module.ts:4:81 - error TS2306: File 'C:/Workspace/....../node_modules/@angular/material/index.d.ts' is not a module.

    4 import { MatInputModule, MatButtonModule, MatSelectModule, MatIconModule } from '[b]@angular/material[/b]';

Open in new window


I looked around, and found the following

https://stackoverflow.com/questions/58594311/angular-material-index-d-ts-is-not-a-module

So it seems that adding angular material to angular 9 has had issues.  I tried to follow what the person with the most upvotes had done, but I don't know how he has integrated material.module.ts into the project.

I created a file in the source folder called material.module.ts with the contents he posted and then referenced this in the app.module.ts.  However this came back with the following:

    ERROR in src/app/app.module.ts:49:5 - error NG6001: The class 'MaterialModule' is listed in the declarations of the NgModule 'AppModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.

    49     MaterialModule
           ~~~~~~~~~~~~~~

      src/app/material.module.ts:115:14
        115 export class MaterialModule {
                         ~~~~~~~~~~~~~~
        'MaterialModule' is declared here.

Open in new window



What do I do to integrate this file into my application, do I have to generate a component or do I have to add a decorator (what's that?)

Thanks
Avatar of Anthony Horner
Anthony Horner

ASKER

Actually looking for more of an opinion before anything, is it even worth going through this to install angular materials? can I do the same with bootstrap.  I'm not looking at mobile development, more for app development that would be accessed on a desktop.
ASKER CERTIFIED SOLUTION
Avatar of Anthony Horner
Anthony Horner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Julian Hansen
material vs bootstrap comes down to how you want your app to look and behave.

Material is more like a framework than Bootstrap Bootstrap is primarily a stylesheet - with some components added on. Material Design is a look and functionality toolkit that is richer than Bootstrap and produces a look and feel (especially on mobile) that has become a standard.
The SO article is quite clear - what they are saying is that you don't do a blanket include of Material into your project - you need to include the different components individually - for each component you want to use.