diff --git a/js/ext/angular/src/directive/ionicTabBar.js b/js/ext/angular/src/directive/ionicTabBar.js index dd13188ad9..30ebf1a14c 100644 --- a/js/ext/angular/src/directive/ionicTabBar.js +++ b/js/ext/angular/src/directive/ionicTabBar.js @@ -13,7 +13,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view']) $ionicViewService.disableRegisterByTagName('tabs'); }]) -.directive('tabs', [function() { +.directive('tabs', ['$ionicViewService', function($ionicViewService) { return { restrict: 'E', replace: true, @@ -80,6 +80,11 @@ angular.module('ionic.ui.tabs', ['ionic.service.view']) if(emitChange) { $scope.$emit('viewState.changeHistory', viewData); } + } else if(emitChange) { + var currentView = $ionicViewService.getCurrentView(); + if(currentView) { + $ionicViewService.goToHistoryRoot(currentView.historyId); + } } }; diff --git a/js/ext/angular/src/service/ionicView.js b/js/ext/angular/src/service/ionicView.js index 7db96ad4ae..43836de5fe 100644 --- a/js/ext/angular/src/service/ionicView.js +++ b/js/ext/angular/src/service/ionicView.js @@ -78,7 +78,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform']) } return null; }; - View.prototype.go = function(opts) { + View.prototype.go = function() { if(this.stateName) { return $state.go(this.stateName, this.stateParams); @@ -143,7 +143,12 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform']) return rsp; } - if(backView && backView.stateId === currentStateId) { + if(viewHistory.forcedNav) { + // we've previously set exactly what to do + ionic.Utils.extend(rsp, viewHistory.forcedNav); + $rootScope.$viewHistory.forcedNav = null; + + } else if(backView && backView.stateId === currentStateId) { // they went back one, set the old current view as a forward view rsp.viewId = backView.viewId; rsp.navAction = 'moveBack'; @@ -311,6 +316,20 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform']) return ionic.Utils.nextUid(); }, + goToHistoryRoot: function(historyId) { + if(historyId) { + var hist = $rootScope.$viewHistory.histories[ historyId ]; + if(hist && hist.stack.length) { + $rootScope.$viewHistory.forcedNav = { + viewId: hist.stack[0].viewId, + navAction: 'moveBack', + navDirection: 'back' + }; + hist.stack[0].go(); + } + } + }, + _getView: function(viewId) { return (viewId ? $rootScope.$viewHistory.histories[ viewId ] : null ); },