我解決了這個問題,因爲它沒有解決類似問題中的問題。沒有MdDialogRef的供應商
我仍然有錯誤'沒有供應商MdDialogRef'即使我跟着官方教程一步一步。
我有兩個組件。第一部分:
import { MdDialog} from "@angular/material";
import { DocumentDialogComponent } from './document-dialog.component';
@Component({
selector: 'documents-list',
template
})
export class DocumentsListComponent {
constructor(
public dialog: MdDialog) {
}
openFormDialog() {
let dialogRef = this.dialog.open(DocumentDialogComponent,
{
}
);
dialogRef.afterClosed().subscribe(result => {
this.selectedOption = result;
});
}
我的第二個組成部分(對話):
import { MdDialogRef} from "@angular/material";
@Component({
selector: 'document-dialog',
template
})
export class DocumentDialogComponent {
constructor(
public dialogRef: MdDialogRef<DocumentDialogComponent>
) {}
}
而我的模塊配置:
import { MaterialModule } from "@angular/material";
import { DocumentsListComponent } from './documents-list.component';
import { DocumentDialogComponent } from './document-dialog.component';
imports : [
MaterialModule.forRoot()
],
declarations: [
AppComponent,
DocumentListComponent,
DocumentDialogComponent
],
entryComponents: [
AppComponent,
DocumentListComponent,
DocumentDialogComponent
],
providers: [
],
bootstrap: [
AppComponent
]
爲什麼還是有錯誤:
Error in ./DocumentsListComponent class DocumentsListComponent - inline template:0:167 caused by: No provider for MdDialogRef!
你在哪裏進口'MaterialModule'? –
在導入部分。我更新了我的問題 – Kivo
您是否嘗試導入'MaterialModule'而不是'MaterialModule.forRoot()'? – gsc