Sorry this is a bit late but here is the basic idea of how to transition to a different view using the angularjs built in $state.transitionTo() and $state.go() capabilities. I hope that you find it helpful.
This example shows an app with two views (and tabs): tab1 and tab2 with a navbar at the bottom of the page. Both views show up in the navbar. When some condition occurs on either page, they transition to the “external” view which is not part of the tab infrastructure and does not have a nav item in the navbar.
The example provided here is not complete because it would be too long. I am only showing the relevant excerpts from the routing (in the app.js file), the controllers (in the controllers.js file) and one example of how you have to duplicate the navbar in the external view (you could, of course, use ng-include).
app.js
In my app.js file I setup the routes for two tabs (tab1 and tab2) as shown below. I also created a completely separate state that is not part of the tabs tree called “external”.
angular.module('starter', ['ionic',
'starter.controllers',
'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// TODO:
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
// Each tab has its own nav history stack:
.state('tab.tab1', {
url: '/tab1',
views: {
'tab-tab1': {
templateUrl: 'templates/tab-tab1.html',
controller: 'Tab1Ctrl'
}
}
})
.state('tab.tab2', {
url: '/tab2',
views: {
'tab-tab2': {
templateUrl: 'templates/tab-tab2.html',
controller: 'Tab2Ctrl'
}
}
})
// This state is not part of the tab tree.
.state('external', {
url: '/external',
templateUrl: 'templates/external.html',
controller: 'ExternalCtrl'
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/tab1');
});
controllers.js
In my controllers.js file I can now use transitionTo() or go() to transition to the new state (“external”).
angular.module('starter.controllers', [])
.controller('Tab1Ctrl', function($scope, $state, appServices) {
$scope.badData = function(bad) {
// function called when bad data is found.
appServices.setBadContext('tab1');
appServices.setBadData(bad);
$state.transitionTo('external'); // transition here
};
})
.controller('Tab2Ctrl', function($scope, $state, appServices) {
$scope.badData = function(bad) {
// function called when bad data is found.
appServices.setBadContext('tab2');
appServices.setBadData(bad);
$state.transitionTo('external');
};
})
.controller('ExternalCtrl', function($scope, $state, appServices) {
$scope.badData = appServices.getBadData();
$scope.badContext = appServices.getBadContext();
$scope.goBack = function() {
$state.transitionTo('tab.' + $scope.badData);
};
})
templates/external.html
The templates/external.html file cannot use the same setup as the tabs because they do not have direct access to tabs.html which means that the navbar (if there is one, has to be duplicated). There may be a way to workaround that but I didn’t take the time to investigate it.
Here is an example.
<ion-view title="External Views">
<ion-content class="has-header has-footer padding">
<h1>External</h1>
<div ng-bind-html="badData"></div>
<div ng-bind-html="badContext"></div>
</ion-content>
<!-- duplicate the tab nav bar -->
<div class="tabs tabs-icon-top">
<a class="tab-item" href="#/tab/tab1">
<i class="icon ion-home"></i>
Tab1
</a>
<a class="tab-item" href="#/tab/tab2">
<i class="icon ion-ios7-information"></i>
Tab2
</a>
</div>
</ion-view>