I wanted to make use of MatSnackBar for displaying notifications on event completion. I imported MatSnackBar in my app module and below is my app.module.ts
...
import { MatSnackBar,
MatSnackBarConfig, ...
} from '@angular/material';
...
@NgModule({
declarations: [...],
imports: [MatSnackBar, MatSnackBarConfig, ...],
providers: [...],
bootstrap: [...],
entryComponents: [...]
})
export class AppModule {
}
Below is my package.json:
{
"@angular/animations": "^5.1.0",
"@angular/cdk": "^5.0.0",
"@angular/cli": "^1.6.1",
"@angular/common": "^5.1.0",
"@angular/compiler": "^5.1.0",
"@angular/compiler-cli": "^5.1.0",
"@angular/core": "^5.1.0",
"@angular/forms": "^5.1.0",
"@angular/http": "^5.1.0",
"@angular/language-service": "^5.1.0",
"@angular/material": "^5.0.0",
"@angular/platform-browser": "^5.1.0",
"@angular/platform-browser-dynamic": "^5.1.0",
"@angular/router": "^5.1.0",
"@swimlane/ngx-charts": "^7.0.1",
"@types/jasmine": "^2.8.2",
"@types/jasminewd2": "^2.0.3",
"@types/node": "^8.0.56",
"angular2-datatable": "^0.6.0",
"core-js": "^2.5.1",
"d3": "^4.10.0",
"ng-http-loader": "^0.2.0",
"ng2-charts": "^1.6.0",
"ng2-handsontable": "^1.0.3",
"rxjs": "^5.5.5",
"zone.js": "^0.8.18"
}
Below is the error I'm getting:
compiler.js:485 Uncaught Error: Unexpected value 'MatSnackBar' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (compiler.js:485)
at eval (compiler.js:15206)
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15189)
at JitCompiler._loadModules (compiler.js:34226)
at JitCompiler._compileModuleAndComponents (compiler.js:34187)
at JitCompiler.compileModuleAsync (compiler.js:34081)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:230)
at PlatformRef.bootstrapModule (core.js:5573)
at eval (main.ts:11)
I'm using angular material 5.0.0, do I need to use some other version to make use of MatSnackBar?
Best Answer
You need to import
and add it under imports
refer the
issue