1

The error occurred while running.

Unexpected value 'MatIconRegistry' imported by the module 'AppModule'. 
Please add a @NgModule annotation

How to solve this error. I added the "@angular/material" in app.module.ts. Still, it's thrown an error.

vishnupriya
  • 37
  • 1
  • 6

1 Answers1

4

Import MatIconModule in your app.module.ts file as below -

import {MatIconModule} from '@angular/material';


imports: [
   // Your other imports
   MatIconModule
],

Hope this will solve your problem

Sneha Pawar
  • 1,097
  • 6
  • 14
  • Thank you so much for your reply. I import the needed Module in app.module.ts. Still thrown an error. I used the MatIconRegistry in the specific component, it has thrown an error like this " Unexpected value 'MatIconRegistry' imported by the module 'AppModule'. Please add a NgModule annotation" – vishnupriya Apr 01 '19 at 06:55
  • have you imported all modules from @angular/material? – Sneha Pawar Apr 01 '19 at 07:04
  • Yes, I imported all modules @angular/material – vishnupriya Apr 01 '19 at 07:08
  • have you imported this import {MatIconRegistry} from '@angular/material/icon'; – Sneha Pawar Apr 01 '19 at 07:18
  • Yes, I imported "import { DomSanitizer } from '@angular/platform-browser'; import { MatIconRegistry } from '@angular/material/icon';" Then I mentioned MatIconRegistry like this in constructor constructor(private router: Router, iconRegistry: MatIconRegistry, sanitizer: DomSanitizer,){ iconRegistry.addSvgIcon('company-heroic', sanitizer.bypassSecurityTrustResourceUrl('assets/images/company-heroic.svg')); } – vishnupriya Apr 01 '19 at 07:43