Couldnât find enough information on how the scope and controller data structure.
I think it would be great if the ionic angular framework talks more about what controllers are available inside the $scope, and also the available methods in different type of controllers
Agreed. Having Ionic out for the last week has really helped us realize how we should adjust the docs and help make it more clear how to do things like this.
Do you have any thoughts on an API for switching tabs that you would prefer? Or maybe we could just make this process more clear, or make it easier to modify the controller from the tabs controller rather than the child tabs.
My understanding:
1.Controllers get executed top-down.
2.Child scope inherits parent scopeâs properties, while parent scope is unware of any new property added to child scope.
3.Which means: when controllerPage is called, the tab bar doesnât exist yet, because TabBarController hasnât be called yet. 4.In controllerTabXs, we can retrieve TabBarController using $scope.tabsController, but we canât use it to set initial selected tab(because the initialization isnât done?), we can only use it in a later triggered event handler.
E.g. Edit ionic seed-projectâs controller.js like this:
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope) { // controllerPage
var tabsController = $scope.tabsController; // undefined
})
.controller('PetsTabCtrl', function($scope, Pets) { // controllerTab1
var tabsController = $scope.tabsController; // ok
tabsController.select(1); // won't work
$scope.$on('tab.shown', function() {
tabsController.select(1); // can work
});
...
})
So:
1.We need a way to set initial selected tab, maybe <tabs tabs-default="1" ...>?
2.We need a way to retrieve tabsController. I think @3dd13âs idea is really great, but maybe we can make it an angular service? E.g.:
<!-- set a name for this tab bar -->
<tabs tabs-name="this-tab-bar-name" ...>
<tab>...</tab>
<tab>...</tab>
...
</tabs>
app.controller('someCtrl', function(..., TabBarManager) {
TabBarManager.find('this-tab-bar-name').select(1); // this won't work
$scope.$on('some event', function() {
TabBarManager.find('this-tab-bar-name').select(1); // this will work
});
});
Please let me know if I am getting something wrong, thanks~
Thanks @cxyokk, that helps! I have been against using Services in cases like this, mainly because I feel you lose some of the niceties of the scope system and instead have to hack your own (like the find function). We kind of took the iOS method of adding attributes to things when there is a parent view controller. Like a child view controller can access the parent view controllers pretty easily.
Let me think on this. We are going to overhaul the nav system a bit so this should fit into that.
It would be nice to use route parameters to choose the selected tab as well.
For example, in the angular config with a route called friends that has a tab bar with âtypesâ of friends, the type parameter would be used to select the correct tab.
Guys been following this thread let me know when there is a clean solution out there from the community or ionic. I also need to change the icons on the tabs dynamically based the tab status even if that tabs is not currently selected. Thx!