Skip to content

Instantly share code, notes, and snippets.

@Ze1598
Created December 28, 2019 14:40
Show Gist options
  • Save Ze1598/fa4e3ec1ee7928fad0756f5894077d0d to your computer and use it in GitHub Desktop.
Save Ze1598/fa4e3ec1ee7928fad0756f5894077d0d to your computer and use it in GitHub Desktop.
Reusable modal component: app.component.ts (first version)
import { Component } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { ModalComponent } from './components/modal/modal.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(public matDialog: MatDialog) { }
openModal() {
const dialogConfig = new MatDialogConfig();
// The user can't close the dialog by clicking outside its body
dialogConfig.disableClose = true;
dialogConfig.id = "modal-component";
dialogConfig.height = "350px";
dialogConfig.width = "600px";
// https://material.angular.io/components/dialog/overview
const modalDialog = this.matDialog.open(ModalComponent, dialogConfig);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment