How can I close just the one of the opened mdDialogs? AngularJs

1.1k Views Asked by At

I have 3 open mdDialogs in my app(not nested in controller) with the 2 of them having the key 'multiple' set to true so they don't close one another. When I call mdDialog.close() or mdDialog.hide() at one of them, both of the child dialogs hide. Is there any way of closing them 1 by 1 ? [Closed]

3

There are 3 best solutions below

0
Gkonst On BEST ANSWER

Actually was a silly mistake guys.. On stacked dialogs with 'multiple' set to true for every child is enough if we just run $mdDialog.hide(). On my issue the problem was that I had 2 calls for the hide function by mistake so, as a result I was closing both dialogs. My bad unnecessary question, but it could be usefull for someone new.

1
kendavidson On

Look at the "custom preset" section and below, https://material.angularjs.org/latest/api/service/$mdDialog. You need to create create an instance object by calling

myPrompt = $mdDialog.prompt();

or

myPrompt = $mdDialog.confirm(); 

or creating a custom preset and then using that instance when showing or closing:

$mdDialog.show(myPrompt);
$mdDialog.close(myPrompt);

Here's a section from the page:

// Dialog #1 - Show simple alert dialog and cache
// reference to dialog instance

function showAlert() {
  alert = $mdDialog.alert()
    .title('Attention, ' + $scope.userName)
    .textContent('This is an example of how easy dialogs can be!')
    .ok('Close');

  $mdDialog
      .show( alert )
      .finally(function() {
        alert = undefined;
      });
}
0
user5714726 On
$mdDialog.show({
  templateUrl: 'dialog.html',
  controller: 'DialogCtrl',
  skipHide:true
})

This works for me. I'm using angularjs-material 1.1.0-rc5