I am using material 2 version 2.0.0-beta.12. I need to adjust the position of the material Modal. I followed this answer to do that. https://stackoverflow.com/a/44238699/8253445 Since MdDialog is not available now I used {MatDialog, MatDialogRef, MAT_DIALOG_DATA}.
constructor(public dialog: MatDialog,public dialModRef:MatDialogRef<any>) {}
When I add MatDialogRef to my constructor it gives me " No provider for MatDialogRef" error. Please can you help me to figure this out?
dialog-overview-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-overview-example-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
, give the name of the Component class you want to open in dialog. Then, add the component class in your entryComponents. – Faisal