Open multiple dialogs?
I would like to open multiple layered dialogs from each controller. Is this possible? Currently if i open a second dialog, the first one closes automatically.
Currently you can only open one dialog at a time. According to the Material Design spec, whether multiple dialogs should be allowed depends on the context and type of dialog:
Avoid opening additional dialogs from within a dialog.
Full-screen dialogs may open additional dialogs, such as pickers, because their design accommodates additional layers of material without significantly increasing the perceived z-depth of the app or increasing visual noise.
Avoid creating dialogs with scrolling content, particularly alerts. Instead, consider alternate containers or layouts that are optimized for reading or interacting with significant amounts of content.
https://www.google.com/design/spec/components/dialogs.html#dialogs-content
@marcysutton, @fhrtms - there have been discussions regarding extensions to $$interimService to cache a LIFO-stack of dialogs; where the hide() will pop off the most recent and hide/close that instance.
@ThomasBurleson ahh! Apologies for prematurely closing. That sounds like similar behavior to the "escape stack" we discussed for Sidenav & Bottom Sheet.
@marcysutton - exactly. After you indicated that the Spec loosely allows mulitple dialogs, I thought we should formally add the feature to Angular Material.
@ThomasBurleson it says "[f]ull-screen dialogs may open additional dialogs, such as pickers, because their design accommodates additional layers". That leaves me with a few spec questions:
- Can a dialog can trigger another dialog as long as it's smaller, and you're in a full-screen experience? What happens on smaller screens?
- Can multiple dialogs be triggered from a page? When one dialog closes, is focus sent to the next dialog?
:+1: for excellent questions.
There's also the iOS style: if a popup opens while another is already open, it will temporarily hide the first popup, show the new popup until the user is done interacting with the new popup, then show the first popup again.
:clap: - I really like that idea also. Sounds like an option flag currentDialog: hide || close || overlay
Consider $timeout() which returns a promise and the `$timeout.cancel(
Since $mdDialog.show() returns a promise, perhaps, $mdDialog.close( <promise> ) could be used to close a specific dialog instance.
Another use case?: I often use modals for create/update forms and I often need to show a confirmation message. Although this is probably better handled by a bottom sheet now. Is this correct?
Or you can use Toast components to show transient messages.
I should have been more clear. By confirmation message, I mean a dialog with "OK", "Cancel" options. Toast messages aren't obvious enough for this purpose, but I do use them to show e.g. a successful save message.
I'm found a nice way to use one dialog with back reference to the parent.

/* BERABEITUNGSDIALOG */
$scope.dialogEditor = function(ev, item) {
var item = angular.copy(item);
$scope.editDialog = $mdDialog;
$scope.editDialog.show({
templateUrl: 'app/views/myDialog.html',
clickOutsideToClose: false,
locals: {local: [$scope.db, item, $scope.editDialog, $scope]},
controller: ['$scope', '$mdDialog', '$mdToast', 'socket', 'local', myDialogController]
}).then(function() {
$scope.alert = 'You said "Okay".';
}, function() {
$scope.alert = 'You cancelled the dialog.';
});
};
var myDialogController = function ($scope, $mdDialog, $mdToast, socket, local) {
$scope.dialog = local[3].dialogEditor;
/* DATENSATZ LOESCHEN */
$scope.deleteData = function() {
var confirm = $mdDialog.confirm()
.title('Möchtest Du den zuvor gewählten Datensatz wirklich löschen?')
.content('Wenn Du dir NICHT sicher bist, dann tippe einfach auf \'NEE, LIEBER DOCH NICHT\' und fahre mit der Bearbeitung fort.')
.ok('Ja, jetzt löschen')
.cancel('Neee, lieber doch nicht');
$mdDialog.show(confirm).then(function() {
$scope.saveData({delete: true});
}, function() {
//$scope.dialogClose();
$scope.dialog(null, local[1]); /* DATENSATZ ZURUECKGEBEN */
});
};
´´´
Thanks for sharing. What tool do you use to capture those gifs? On 9 Dec 2014 02:28, "fhrtms" [email protected] wrote:
I'm found a nice way to use one dialog with back reference to the parent.
[image: Image of Yaktocat] https://camo.githubusercontent.com/93e2c74cf5c2f8cca68d73dcf28a5a4f094978a1/687474703a2f2f692e696d6775722e636f6d2f4e423258774e342e6769663f31
/* BERABEITUNGSDIALOG */ $scope.dialogEditor = function(ev, item) { var item = angular.copy(item); $scope.editDialog = $mdDialog; $scope.editDialog.show({ templateUrl: 'app/views/myDialog.html', clickOutsideToClose: false, locals: {local: [$scope.db, item, $scope.editDialog, $scope]}, controller: ['$scope', '$mdDialog', '$mdToast', 'socket', 'local', myDialogController] }).then(function() { $scope.alert = 'You said "Okay".'; }, function() { $scope.alert = 'You cancelled the dialog.'; }); };
var myDialogController = function ($scope, $mdDialog, $mdToast, socket, local) { $scope.dialog = local[3].dialogEditor;
/* DATENSATZ LOESCHEN */ $scope.deleteData = function() { var confirm = $mdDialog.confirm() .title('Möchtest Du den zuvor gewählten Datensatz wirklich löschen?') .content('Wenn Du dir NICHT sicher bist, dann tippe einfach auf \'NEE, LIEBER DOCH NICHT\' und fahre mit der Bearbeitung fort.') .ok('Ja, jetzt löschen') .cancel('Neee, lieber doch nicht'); $mdDialog.show(confirm).then(function() { $scope.saveData({delete: true}); }, function() { //$scope.dialogClose(); $scope.dialog(null, local[1]); /* DATENSATZ ZURUECKGEBEN */ }); };´´´
— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/698#issuecomment-66262302.
I like this one on Windows: screentogif.codeplex.com
No install, very handy and easy to use!
and this on Linux: recorditnow.sourceforge.net
@fhrtms thanks for that code! It took me a while to figure out what you were doing since there were no english comments but it seems you are just saving the main dialog's scope before opening the second dialog, and then if the user cancels this second one, you just reopen the main with the old scope, is that right? I'm going to do it a bit differently from you, but the idea remains the same. Thanks a lot!
@MarcosPortugal: Yes, this is what i do.
I really need nested dialogs for our application, so i tinkered with the source code. I didn't test it very well but i think its working, at least for us. Its a quick solution (manipulating the z-index like i do is not very nice, i guess).
If a new dialog opens, old dialogs won't close. If $mdDialog.cancel() is called the most recent dialog will be closed.
https://github.com/hayloft/material/commit/2ad189a6adaa49975ed82df5ad0e54db9d51629d Obviously some unit tests break with this commit...
Updated for 0.8.3: https://github.com/hayloft/material/commit/16507349d8c13f07ff8267d8bd364d9003ebd1c6
Has anyone from core team been able to try out @benn0r's code? The change seems easy to digest.
Is it possible to update template of current dialog instead showing different dialog?