Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a simple alert dialog in Material Angular

I'm using Material Angular (from Angular Material). The examples in the site seem a Little too overcomplicated and every other tutorial in the internet seems either outdated or to be using AngularJS instead. How can I show a simple alert (just like Android's AlertDialog) with a title, a message and a confirm/cancel button?

like image 390
Washington A. Ramos Avatar asked Mar 25 '18 02:03

Washington A. Ramos


People also ask

What is MatDialog used for in angular material?

The MatDialog service can be used to open modal dialogs with Material Design styling and animations.

How do you use MatDialogRef?

In the dialog component, we need to create an instance of 'MatDialogRef' which we should import from '@angular/material/dialog'. Import 'MatDialogModule' from '@angular/material' in app. module. ts file.

How do I get data from MatDialog?

You can pass any kind of data to the component by adding data to the MatDialog's open() options. }, }); You can retrieve the data by injecting MAT_DIALOG_DATA in the opened component.


1 Answers

I had used a sweet Alert. https://www.freakyjolly.com/angular-sweetalert2-tutorial/#.X2nNxmgzZPY

It´s the most easy and fast method to create alerts in angular.

$ npm install --save sweetalert2

Use import Swal from 'sweetalert2'; in your TS file together with the Alert Swal.fire('This is a simple and sweet alert')

like image 158
Felipe Clemente Avatar answered Sep 20 '22 16:09

Felipe Clemente