Can't resolve all parameters for MatDialogRef angular 4
Remove MatDialogRef
from the list of providers.
This isn't a provider, this is a reference to an Object (it ends with Ref
)
Hope this helps this is what I have done:
At the component:
import { MatDialog } from '@angular/material';
import { DialogComponent } from './dialogs'; // component name of dialog can add multiple in here.
@Component({
selector: 'yourComponent',
templateUrl: './yourComponent.html'
})
export class YourComponent {
private dialogRef: any;
constructor(public dialog: MatDialog) {
openPopup(){
this.dialogRef = this.dialog.open(DialogComponent , {
width: '250px',
height: '25%',
data: { errorcode: errorCode, errormessage: errorMessage }
});
this.dialogRef.updatePosition({ top: '3%', left: '20%' });
}
In the module:
import { DialogComponent } from './dialogs'; // component name of dialog
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MatDialogModule } from '@angular/material';
@NgModule({
declarations: [
DialogComponent
],
imports: [
BrowserModule,
MatDialogModule
],
entryComponents: [
DialogComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
})
And at last, the dialog(s):
import {Component, OnInit} from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
@Component({
selector: 'app-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.css']
})
export class DialogComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<DialogComponent>,
@Inject(MAT_DIALOG_DATA) private data: any) { } // this.data.errormessage contain error message. Not sure if need OnInit.
ngOnInit() {
} // I have not used this. Instead, I have put the data in HTML and click on buttons from there to interact with the component.
}