0

I am having a problem with ngDialog (https://github.com/likeastore/ngDialog), I have 1 dialog open and when the user clicks a button it pops up another modal on top as an alert. I want to close the alert dialog via a button but when I use ngDialog.close() is closes all the active modals.

I realise the docs state that if you do not pass an id then it acts as closeAll(), therefore I need to give it an id. So when I use ngDialog.open() I give it an id of alert and then I use ngDialog.close("alert"), however this still closes all the modals....

I have created a plunker to try and show what I am doing and it is acting the same way...http://plnkr.co/0bg1VB7QuEZxIdakfoBr

scope.closeThisDialog = function() {
  ngDialog.close("secondDialog");
};

If you inspect at the source it also shows that the id is not showing up either, I suspect that this is why both modals are closing still.

Can anyone shed any light on what I am doing wrong.

Ben
  • 303
  • 1
  • 6
  • 18

2 Answers2

0

You shouldn't overwrite the closeThisDialog method. The documentation says ".closeThisDialog(value) method gets injected to passed $scope.", since your directive has its own scople, you should be able to find the injected method from parent scope. So your method should be changed to like below.

scope.closeThisDialog = function() {
    //ngDialog.close("secondDialog");
    scope.$parent.closeThisDialog();
  };

http://plnkr.co/edit/t7xVrsGfq7YtWxbGbwn6?p=preview

sdfacre
  • 1,273
  • 7
  • 7
  • I didn't intend to overwrite the closeThisDialog method, that was just my bad method naming, I have changed it to finish. The idea behind my code is that all the directives are self contained so using $parent breaks this by forcing my directive to have knowledge of its parent. – Ben Mar 30 '16 at 02:38
  • to me, a dialog must be within certain context, so it is not really self contained. or you can do, if(scope.closeThisDialog) scope.closeThisDialog(); else scope.$parent.closeThisDialog(); – sdfacre Mar 30 '16 at 02:46
0

I have got around not being able to get the dialogs id by passing it though the scope and putting on my directive

scope.openProfileDialog = function() {
  var profileDialogScope = scope.$new();
  profileDialogScope.customerNumber = scope.customerNumber;

  var profileDialog = ngDialog.open({
      plain: true,
      template: "<profile-dialog customer-number='{{ customerNumber }}' dialog-id='{{dialogId}}'></profile-dialog>",
      closeByDocument : false,
      name: "profileDialog",
      scope: profileDialogScope,
      id: "profileDialog"
  });

  profileDialogScope.dialogId = profileDialog.id;
};

Then in the profile-dialog directive I have

scope: {
  customerNumber : "@",
  dialogId: "@"
},

and this is in the link section

scope.finish = function() {
  ngDialog.close(scope.dialogId);
};
Ben
  • 303
  • 1
  • 6
  • 18