3

To automatically close a ngDialog after the successful login, I used the below approach.

HTML template,

<a href="" ng-click="signin()">Log In</a>
<a href="" id="btnClose" ng-click="closeThisDialog()"   
style="display:none;">Close</a>

In the controller, the signin method has the following code to trigger the click event of close button,

$timeout(function () {
    var btnClose = document.getElementById('btnClose');
    angular.element(btnClose).triggerHandler('click');
}, 0);

Is there any better approach to close the ngDialog automatically?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Saravanan Sachi
  • 2,572
  • 5
  • 33
  • 42

3 Answers3

1

You can simple use closeThisDialog just like below in your signin method. This will close the dialog after click the log in button.

$scope.signin = function() {
     $scope.closeThisDialog();
};
erhun
  • 3,549
  • 2
  • 35
  • 44
1

I created a little directive for this kind of stuff:

app.directive('closeDialog', function(ngDialog, $timeout) {
  return {
    link: function(scope, element, attrs) {
      if(attrs.closeDialog) {
        $timeout(function(){ngDialog.close()}, attrs.closeDialog * 1000);
      }
      element.bind('click', function(element) {
        ngDialog.close();
      })
    }
  }
});

You can use it by simple add the directive in your custom closing tag:

<button close-dialog="5">Close</button>

This dialog will close after 5 seconds.

0
// inside dialog's controller
function sigin() {
// do sigin
    .then(function () {
        that.closeThisDialog();
    })

}

// Page's controller 
var dialog = ngDialog.open({
   template  : 'scripts/modals/signup.tpl.html',
   ...
   etc.
});
Tsanko
  • 1
  • 3