diff --git a/js/angular/service/history.js b/js/angular/service/history.js index 8e453aa0230..254b0efc5df 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -42,7 +42,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ var DIRECTION_NONE = 'none'; var stateChangeCounter = 0; - var lastStateId, nextViewOptions, nextViewExpireTimer, forcedNav; + var lastStateId, nextViewOptions, deregisterStateChangeListener, nextViewExpireTimer, forcedNav; var viewHistory = { histories: { root: { historyId: 'root', parentHistoryId: null, stack: [], cursor: -1 } }, @@ -367,6 +367,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ hist.stack.push(viewHistory.views[viewId]); } + deregisterStateChangeListener && deregisterStateChangeListener(); $timeout.cancel(nextViewExpireTimer); if (nextViewOptions) { if (nextViewOptions.disableAnimate) direction = DIRECTION_NONE; @@ -682,6 +683,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ * ``` */ nextViewOptions: function(opts) { + deregisterStateChangeListener && deregisterStateChangeListener(); if (arguments.length) { $timeout.cancel(nextViewExpireTimer); if (opts === null) { @@ -690,9 +692,11 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ nextViewOptions = nextViewOptions || {}; extend(nextViewOptions, opts); if (nextViewOptions.expire) { - nextViewExpireTimer = $timeout(function() { - nextViewOptions = null; - }, nextViewOptions.expire); + deregisterStateChangeListener = $rootScope.$on('$stateChangeSuccess', function() { + nextViewExpireTimer = $timeout(function(){ + nextViewOptions = null; + }, nextViewOptions.expire); + }); } } }