Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui tab with seperate controllers for each tab

I would like to make a bootstrap tabset with each tab having it's own controller. Can anyone point me in which direction I should go.

Currently I have made several difference controllers, which I would like to be used in a tabset instead of having them displayed as a different route.

I know I could fake it by having the tabset in the difference controller templates displaying the given controllers tab as active, but I would like to be able to have a main TabController with several child controllers (for each tab)

like image 786
kamante Avatar asked Jan 09 '14 10:01

kamante


1 Answers

If you are using angular ui router you can use nested states to do this.

  • Create an abstract state with a view that contains the tabs and a nested ui-view
  • Create a child state for each of your tabs, each inheriting from the abstract state
  • Each child state can set the content of the nested ui-view, and define a controller

     $stateProvider.state( 'tabs', {
        abstract: true,
            url: 'tabs',
            views: {
              "tabs": {
                controller: 'TabsCtrl',
                templateUrl: 'tabs.html'
              }
            }
          })
          .state('tabs.tab1', {
              url: '',  //make this the default tab
              views: {
              "tabContent": {
                controller: 'Tab1Ctrl',
                templateUrl: 'tab1.html'
              }
            }
          })
          .state('tabs.tab2', {
              url: '/tab2',
              views: {
              "tabContent": {
                controller: 'Tab2Ctrl',
                templateUrl: 'tab2.html'
              }
            }
          });
    
like image 52
Dan Avatar answered Oct 08 '22 02:10

Dan