As best I can tell, the only way to know what’s going on in a tabbed scenario is to put a new controller on each tab in a set of tabs. This is how the ionic-angular-cordova-seed example does it.
<tab title="Pets" icon="icon ion-home" ng-controller="PetsTabCtrl">
See this plunker updated to 0.9.19 : Plunker - ionic-angular-cordova-seed on plunker with 0.9.19 Alpha Koala
So, even though an app may have a router or state controller (appCtrl
in the sample) , you need a new controller for the tabs. (Trying to put the main controller on each <tab>
or the overarching <tabs>
causes an injection error.
Is there a way for the active route/state controller to know what is happening in the tabs or to change the current tab?
I’ve dabbled with :
$scope.$on('viewState.changeHistory', function(viewData) {
console.log('State has changed!');
console.log(viewData);
})
on the main controller. It does work. But to get information about what tab is active, you have to go digging through the targetScope
and controllers
of viewData
.
So, basically I am saying right now, each tab seems to need it’s own controller and there is no way to way a single controller to rule/supervise them all?
Other conversations like this :