tl;dr
feature request: ontabchange event to be triggered from $ionicTabsDelegate service
Hey guys,
Am I the only one who needs ontabchange event for the tabs directive ?
Here is my problem:
My bussines case requires inline views inside tabs ( I just dont need history for navigating between the tabs )
tabs
tab1
inline view ng-controller=Ctrl1
tab2
inline view ng-controller=Ctrl2
tab3
inline view ng-controller=Ctrl3
Lets say every controller has some initial data fetching, performed at instantiation time.
angular.module('foo').controller('Ctrl1', function($scope, $http){
$scope.data = $http.get('foo1')
})
angular.module('foo').controller('Ctrl2', function($scope, $http){
$scope.data = $http.get('foo2')
})
angular.module('foo').controller('Ctrl3', function($scope, $http){
$scope.data = $http.get('foo3')
})
This way all three controllers will be instantiated at the same time, thus our application will make 3 ajax requests eagerly.
In order to activate the according controller lazily and thus performing only the needed ajax request, I need a way to know when particular tab is shown .
Currently this can be done this way:
- set onclick listener on every tab;
- do your initialization logic in the corresponding controller;
- manually switch tabs from the controller ( since we introduced custom on-click listener and the tabs wont switch )
This feels dirty.
My proposal is to introduce ontabchange event which will be triggered on tab change and every controller can subscribe to it via the $ionicTabsDelegate service.
I want to implement this if you guys are ok with it.