0

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?

harishr
  • 17,807
  • 9
  • 78
  • 125
  • See my answer here: http://stackoverflow.com/questions/25445949 – apairet Aug 27 '14 at 20:42
  • can you put it as answer. – harishr Aug 28 '14 at 05:22
  • can you put it as answer. also i don't think its a duplicate the scenario and answer is same, but the context i came from was different and was not able to get any question in my context. hence i asked the question. there are many similar question on SO. but not always duplicate. anyways. thanks a lot for the answer. could not have solved the problem without your answer. so thanks a lot. – harishr Aug 28 '14 at 05:27
  • OK, here you go. rgds – apairet Aug 28 '14 at 05:45
  • 1
    Could you test the answer and validate it if it fits your needs? Thanks – apairet Oct 05 '14 at 08:09

1 Answers1

2

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);
        }
    };
}]);
apairet
  • 3,162
  • 20
  • 23