Created
December 28, 2019 17:25
-
-
Save Ze1598/24eed425a9cafe3e29e4e822a64c953a to your computer and use it in GitHub Desktop.
Reusable modal component: app.component.ts (second version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
dialogConfig.data = { | |
name: "logout", | |
title: "Are you sure you want to logout?", | |
description: "Pretend this is a convincing argument on why you shouldn't logout :)", | |
actionButtonText: "Logout", | |
} | |
// 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