Error while trying to load a mat-table with angular 6

Asked

Viewed 89 times

0

Starting with Angular 6. When trying to create a table, based on an example I picked up, I started having the following problem. I added in my module main, these lines:

import { MatInputModule, MatPaginatorModule, MatProgressSpinnerModule, 
         MatSortModule, MatTableModule } from '@angular/material';

and in the section Imports I also added, as below:

imports: [
    BrowserModule,
    FormsModule,
    BrowserAnimationsModule,
    HttpClientModule,
    MatInputModule,
    MatTableModule,
    MatPaginatorModule,
    MatSortModule,
    MatProgressSpinnerModule
  ],

Well, it turns out on that line I have the following mistake:

from '@angular/material';

[ts] Cannot find module@angular/material'.

And also in the Imports, gives error in these two guys

BrowserAnimationsModule,
HttpClientModule,

So what I did. I went to package json. of the application and added this line:

"@angular/material": "^6.0.3",

well, anyway the error persists. Has anyone ever gone through this and managed to resolve? I’m searching but so far no conclusive answer.

  • well, I just found a link and I’m gonna test the guys' response and see what happens.

  • You would actually do an npm install after inserting the line into package.json ?

  • @Lucasbrogni, yes I did it now. It didn’t solve, but I didn’t restart VS Code. I’ll do it now. I did it: npm install --save @angular/material

  • did just npm install --save @angular/material @angular/cdk I’ll see if you’ve solved

  • still persists, even restarting VS Code

1 answer

1

Through the documentation of the angular material each import has its own path. This is to try to be as modular as possible. For example:

import {MatInputModule} from '@angular/material/input';
  • Eduardo, how I made so the Imports: import { Matinputmodule, Matpaginatormodule, Matprogressspinnermodule, Matsortmodule, Mattablemodule } from '@angular/material'; I must slice one at a time?

  • this of each one of them

  • 1

    https://material.angular.io/components/input/api

  • Only see the tab api of each component

  • I reinstalled @angular/material and this time it worked. And I don’t know why yesterday didn’t, yesterday I gave a npm install g @angular/material --save and today I removed the g. I think that was it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.