Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a promise be returned by a dialog popup in angularjs Material Design?

I was reading up on details of mdDialog in Material Design, and couldn't understand why an alert popup would return a promise. Can someone explain how a promise is returned by a mdDialog through an example?

The documentation for Material Design mdDialog said the following:

$mdDialog opens a dialog over the app to inform users about critical information or require them to make decisions. There are two approaches for setup: a simple promise API and regular object syntax.

like image 825
Sunil Avatar asked Apr 28 '15 19:04

Sunil


Video Answer


1 Answers

It returns a promise because you probably want to react to future events in different way, like close (resolve the promise) and cancel (reject it).

mdDialod.show() returns a promise, as written in documentation, so you can just resolve or reject it (as mentioned above, with close and cancel methods on $mdDialog service).

Here is a simple example as you requested (open the console to see how it logs the appropriate text for each event).

like image 166
Roy Miloh Avatar answered Oct 22 '22 00:10

Roy Miloh