angular - Ovärt värde 'MatDialogRef' importerat av modulen 'AppModule'. Vänligen lägg till en @NgModule-annotering
Jag försöker integrera Angular Material i Angular men får följande fel. Programmet kompileras framgångsrikt men får detta problem i webbläsaren.
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)
Jag har importerat MatDialogRef i app.module.ts
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
MatButtonModule,
MatDialogModule,
MatDialogRef,
ReactiveFormsModule,
HttpModule,
HttpClientModule,
AppRoutingModule
],
Jag har också importerat det i komponenten där dialog-HTML är sparad.
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
export class ComposeMailComponent implementerar OnInit {
constructor(private dialogRef: MatDialogRef<ComposeMailComponent>,
@Inject(MAT_DIALOG_DATA) private data) {}
ngOnInit() {
}
}
Svar #1
Du behöver inte importera MatDialogRef i app.module.ts, ändra
Från
importera { MatDialogModule, MatDialogRef } från '@angular/material/dialog';
Till
importera { MatDialogModule } från '@angular/material';
och ta bort MatDialogRef från imports-arrayen
Svar #2
lägg till dessa i filen app.module.ts
import { MatDialogModule } från '@angular/material';
imports: [ MatDialogModule ],
det kommer att fungera bra