Reputation: 18055
In my angularjs app, use gets automatically logged out if user is inactive for certain minutes. The problem is, in case modal dialog is open, the route change and use gets logged out but the modal remains open.
one way to solve this would be closing the modal on scope.$destroy
. but then I would have to remember to write that code in every controller, which is not an ideal solution, because I might forgot to do so.
is there any other generic way to solve this problem?
Upvotes: 0
Views: 1760
Reputation: 3172
You can inject the $modalStack service and call the function $modalStack.dismissAll
, see the code on github for details:
https://github.com/angular-ui/bootstrap/blob/master/src/modal/modal.js#L287
Suppose an autoLogout factory called and a closeModals function:
myApp.factory('autoLogout', ['$modal', '$modalStack' function($modal, $modalStack) {
return {
// all your current code
closeModals: function(reason) {
$modalStack.dismissAll(reason);
}
};
}]);
Upvotes: 2