我正在使用material 2 version 2.0.0-beta.12。我需要調整材質Modal的位置。我遵循這個答案來做到這一點。 https://stackoverflow.com/a/44238699/8253445由於MdDialog現在不可用,我使用{MatDialog,MatDialogRef,MAT_DIALOG_DATA}。沒有MatDialogRef的供應商
constructor(public dialog: MatDialog,public dialModRef:MatDialogRef<any>) {}
當我將MatDialogRef添加到我的構造函數時,它給了我「沒有MatDialogRef的提供者」錯誤。請你能幫我弄清楚這一點嗎?
對話框的概述,example.ts
import {Component, Inject} from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from
'@angular/material';
@Component({
selector: 'dialog-overview-example',
templateUrl: 'dialog-overview-example.html'
})
export class DialogOverviewExample {
animal: string;
name: string;
constructor(public dialog: MatDialog,public
dialModRef:MatDialogRef<any>) {}
openDialog(): void {
let dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '500px',
data: { name: this.name, animal: this.animal }
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
}
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog {
constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
onNoClick(): void {
this.dialogRef.close();
}
}
app.module.ts
entryComponents: [DialogOverviewExample,DialogOverviewExampleDialog]
對話框的概述 - 例如,dialog.html
<h1 md-dialog-title>Hi {{data.name}}</h1>
<div md-dialog-content>
<p>What's your favorite animal?</p>
<md-form-field>
<input mdInput tabindex="1" [(ngModel)]="data.animal">
</md-form-field>
</div>
<div md-dialog-actions>
<button md-button tabindex="2">Ok</button>
<button md-button (click)="onNoClick()" tabindex="-1">No Thanks</button>
</div>
而不是'any',給出想要在對話框中打開的Component類的名稱。然後,在您的entryComponents中添加組件類。 – Faisal
我現在這樣做..我仍然得到相同的錯誤:( –