Close ngDialog automatically
To automatically close ngDialog
after successful login, I used the approach below.
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 method signin
has the following code to trigger a close button click,
$timeout(function () {
var btnClose = document.getElementById('btnClose');
angular.element(btnClose).triggerHandler('click');
}, 0);
Is there a better approach for automatic closing ngDialog
?
+3
source to share
3 answers
You can just use closeThisDialog like below in your signin method. This will close the dialog after clicking the login button.
$scope.signin = function() {
$scope.closeThisDialog();
};
+1
source to share
I created a little directive for this kind of thing:
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 simply by adding a directive to your custom close tag:
<button close-dialog="5">Close</button>
This dialog will close after 5 seconds.
+1
source to share