angularjs - AgularJS: How to close active $modal on session timeout -
i'm developing spa, on session timeout redirect user login page. here implementation
.run(['$rootscope', '$state', '$location', function ($rootscope, $state, $location) { $rootscope.$watch(function detectidle() { var = new date(); if (now - lastdigestrun > 20 * 60 * 1000) { $location.path('/login'); settimeout(function () { alert("your session has expired. please log in again"); }, 1000); } }); }])
problem: if application timeouts when $modal open, page redirect login page $modal not close.
please me solve problem
thanks
update: sorry answering own question, working solution given below:
.run(['$rootscope', '$state', '$location', function ($rootscope, $state, $location) { var issessiontimeout = false; $rootscope.$watch(function detectidle() { var = new date(); if (now - lastdigestrun > 20 * 60 * 1000) { issessiontimeout = true; $location.path('/login'); settimeout(function () { alert("your session has expired. please log in again"); }, 1000); } }); $rootscope.$on('$statechangesuccess', function () { if (issessiontimedout) { $modalstack.dismissall(); } }); }])
when session expired redirect user login
$location.path('/login');
so in order close open modals in 1 place after redirect can subscribe on $routechangesuccess
event of $rootscope
, use $modalstack.dismissall();
app.run(['$rootscope', '$modalstack', function ($rootscope, $modalstack) { $rootscope.$on('$routechangesuccess', function () { $modalstack.dismissall(); }); }]);
Comments
Post a Comment