Angular2 material dialog self close

If you wanna close it from the dialog:

constructor(private dialogRef: MatDialogRef<MyDialogComponent>){ }

closeDialog(){
  this.dialogRef.close();
}

If you wanna close it from the parent of the dialog:

constructor(private matDialog: MatDialog){}

//anywhere
let dialogRef = this.matDialog.open(MyDialogComponent);
dialogRef.close();

As stated in the accepted answer

this.dialogRef.close();

closes the dialog. But most of the time we want the response from server to be rendered immediately without refreshing the page. To do that, we pass the response as an arugument to the close method as shown below

this.dialogRef.close(response);

If you do this, you don't need to do the event emmiter approach found in the docs which is

<button mat-button [mat-dialog-close]="response" cdkFocusInitial>Add</button>

since it closes the dialog before the asynchronous operation finishes.