diff --git a/js/angular/directive/sideMenus.js b/js/angular/directive/sideMenus.js index 11dd2ea4c7..62cb662e2f 100644 --- a/js/angular/directive/sideMenus.js +++ b/js/angular/directive/sideMenus.js @@ -88,6 +88,12 @@ IonicModule $ionicBody.enableClass(isAsideExposed, 'aside-open'); }); + $scope.$on('$ionicView.beforeEnter', function(ev, d){ + if (d.historyId) { + $scope.$activeHistoryId = d.historyId; + } + }); + $scope.$on('$destroy', function() { $ionicBody.removeClass('menu-open', 'aside-open'); }); diff --git a/js/angular/service/history.js b/js/angular/service/history.js index df7eea6cce..c8da977b17 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -663,13 +663,37 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ var climbScope = scope; var currentHistoryId = this.currentHistoryId(); + var foundHistoryId; + while (climbScope) { if (climbScope.$$disconnected) { return false; } - if (currentHistoryId && (currentHistoryId == climbScope.$historyId || currentHistoryId == climbScope.$activeHistoryId)) { - return true; + + if (!foundHistoryId && climbScope.hasOwnProperty('$historyId')) { + foundHistoryId = true; } + + if (currentHistoryId) { + if (climbScope.hasOwnProperty('$historyId') && currentHistoryId == climbScope.$historyId) { + return true; + } + if (climbScope.hasOwnProperty('$activeHistoryId')) { + if (currentHistoryId == climbScope.$activeHistoryId) { + if (climbScope.hasOwnProperty('$historyId')) { + return true; + } + if (!foundHistoryId) { + return true; + } + } + } + } + + if (foundHistoryId && climbScope.hasOwnProperty('$activeHistoryId')) { + foundHistoryId = false; + } + climbScope = climbScope.$parent; } diff --git a/js/angular/service/viewSwitcher.js b/js/angular/service/viewSwitcher.js index b4957b074f..16887b7409 100644 --- a/js/angular/service/viewSwitcher.js +++ b/js/angular/service/viewSwitcher.js @@ -69,6 +69,7 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe view = view || {}; return { viewId: view.viewId, + historyId: view.historyId, stateId: view.stateId, stateName: view.stateName, stateParams: view.stateParams diff --git a/test/unit/angular/service/history.unit.js b/test/unit/angular/service/history.unit.js index dc176447de..05df6f90e5 100644 --- a/test/unit/angular/service/history.unit.js +++ b/test/unit/angular/service/history.unit.js @@ -1195,7 +1195,43 @@ describe('Ionic History', function() { } } } - } + }; + expect(ionicHistory.isActiveScope(scope)).toEqual(true); + }); + + it('should be active when activeHistoryId found before historyId, for tabs controller', function() { + ionicHistory.currentView({ + historyId: '123' + }); + + var scope = { + $parent: { + $parent: { + $activeHistoryId: '123', + $parent: { + $historyId: 'xyz' + } + } + } + }; + expect(ionicHistory.isActiveScope(scope)).toEqual(true); + }); + + it('should be active when historyId found before activeHistoryId', function() { + ionicHistory.currentView({ + historyId: '123' + }); + + var scope = { + $parent: { + $parent: { + $activeHistoryId: 'xyz', + $parent: { + $historyId: '123' + } + } + } + }; expect(ionicHistory.isActiveScope(scope)).toEqual(true); });