我正在嘗試創建一個對話框,如材料設計頁面Here中所示。我可以讓按鈕顯示出來,點擊它,對話框出現並且頁面如預期變暗,但沒有文字出現。我覺得我很接近,但我無法弄清楚我要去哪裏錯了。任何幫助表示讚賞,謝謝!Angular 2和Material Designs - 示例對話框爲空
這裏是我的代碼:
import { Component, OnInit } from '@angular/core';
import {MdDialog} from '@angular/material';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(public dialog: MdDialog) { }
openDialog() {
this.dialog.open(DialogOverviewExampleDialog);
}
ngOnInit() {
}
}
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: './dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog {}
你得到一個錯誤的控制檯?因爲沒有構造函數,所以你在'DialogOverviewComponent'中也缺少'dialogRef'依賴項。 –
是的。它說,找不到名稱爲'DialogOverviewExampleDialog'。)和找不到DialogOverviewExampleDialog的組件工廠。你把它添加到@ NgModule.entryComponents?即使它在那裏。你能解釋一下dialogRef的含義嗎?稍後會在文檔中提到它,但它不在示例代碼中。 – gv0000
如果我嘗試使用DialogOverviewExampleDialogComponent也給出了一個錯誤,「沒有爲DialogOverviewExampleDialog找到組件工廠,是否將它添加到@ NgModule.entryComponents?」 – gv0000