I am currently facing an issue while trying to incorporate Angular Material into my Angular project. Despite successful compilation of the program, I encounter an error when running it in the browser.
Uncaught Error: Unexpected value 'MatDialogRef' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (compiler.js:485)
at eval (compiler.js:15226)
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15201)
at JitCompiler._loadModules (compiler.js:34385)
at JitCompiler._compileModuleAndComponents (compiler.js:34346)
at JitCompiler.compileModuleAsync (compiler.js:34240)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:239)
at PlatformRef.bootstrapModule (core.js:5551)
at eval (main.ts:11)
In my app.module.ts file, I have imported MatDialogRef as shown below:
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
MatButtonModule,
MatDialogModule,
MatDialogRef,
ReactiveFormsModule,
HttpModule,
HttpClientModule,
AppRoutingModule
],
Additionally, I have included the import statement for MatDialogRef in the component where the dialog HTML is stored:
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
Here is an excerpt from the code in the component:
export class ComposeMailComponent implements OnInit {
constructor(private dialogRef: MatDialogRef<ComposeMailComponent>,
@Inject(MAT_DIALOG_DATA) private data) {}
ngOnInit() {
}
}