ionic tabs: How to reuse the same detail page accross different tabs

本秂侑毒 提交于 2019-12-04 10:48:31

Posted a response over in the Ionic forum, but figured I'd dup it here as well...

I had a similar issue where I needed to reuse templates across tabs and maintain keeping the user in the active tab. I ended using $ionicTabsDelegate and in my controllers, grabbed the tab index by doing something like this $scope.selectedTabIndex = $ionicTabsDelegate.selectedIndex();

My issue was having the correct routes. I created routes for each tab that referenced the same template but had a different URL. In my templates, I then loaded in the selectedTabIndex, and when I needed to link to another view, I passed the tab index in my function to change states.

For example, in the template I am re-using, I have this:

ng-click="viewUser(id, selectedTabIndex);"

and in my controller, I have something like this:

$scope.viewUser = function(uid, tabIndex){
    if(tabIndex == 2){
        $state.go('tab.me-user',{ uid: uid});
    } else {
        $state.go('tab.user-profile',{ uid: uid});
    }
};

I would rather have multiple routes than multiple templates, so this worked well for me. I'd be very interested to see if someone else comes up with another way to achieve this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!