4

I need to open multiple ngDialog with same id, when clicking the close button it should close only the currently opened ngDialog.

For closing ngDialog I need to call one event which collects the data then closes the ngDialog.

user2021347
  • 69
  • 1
  • 1
  • 3

5 Answers5

8

It depends if you're trying to close it (1) from its own controller, or (2) the controller that instantiates it:

(1) From its own controller:

scope.closeThisDialog(value);

see doc: https://github.com/likeastore/ngDialog

(2) From controller that instantiates it:

var dialog = ngDialog.open(); 
// for closing the dialog call dialog.close()

As mentioned by Satish Salvador's response.

Cheers!

mika
  • 1,411
  • 1
  • 12
  • 23
3

Assign the ngDialog.open() to a variable like var dialog = ngDialog.open(); for closing the dialog call dialog.close()

sathish salvador
  • 320
  • 5
  • 16
  • this is correct if you are closing dialog from same function , but if you are opening dialog from one function , how can you close it inside another function ? – Arash Apr 24 '16 at 05:07
  • @MichaelFulton did you find the solution for it? – Ali Nouman May 12 '16 at 14:11
  • @HumanLove Yes my issue was fixed good enough for my purposes by disabling animations. I have posted an answer. You can specify the disableAnimations option when creating the dialog. Issues thread described here https://github.com/likeastore/ngDialog/issues/319#issuecomment-215273260 – Michael Fulton May 12 '16 at 22:05
  • @Arash You could have the var dialog outside the function, check the dialog state on function call with the var dialog and perform your actions – sathish salvador May 13 '16 at 08:15
2

You could use .getOpenDialogs()

There is a method on ngDialog object called getOpenDialogs. What you could with this function is to get a list of all opened dialogs and close the one you are interested in by calling .close() on the "selected" one.

Vladimir Zdenek
  • 2,270
  • 1
  • 18
  • 23
1

In some cases, you can avoid this issue by specifying disableAnimation options when creating the dialog:

ngDialog.open({
  template: 'template.html',
  appendClassName: 'ngdialog-custom',
  disableAnimation: true
});
Michael Fulton
  • 4,608
  • 3
  • 25
  • 41
  • It worked in my case but I would like to know the exact reason for this. @michael-fulton Can you please explain this. – ba1ar Nov 07 '16 at 11:22
0

Beyond closeThisDialog() you can do:

vm.myDialog = ngDialog.open(... omissis ...);
...
vm.myDialog.close();

or

vm.myDialog = ngDialog.open(... omissis ...);
...
ngDialog.close(vm.myDialog.id);    
7uc4
  • 194
  • 1
  • 8