6

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)

1
  • 1
    Please insert your code what you have done?? Commented Jan 9, 2014 at 10:42

2 Answers 2

8

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'
              }
            }
          });
    
Sign up to request clarification or add additional context in comments.

2 Comments

Adding the html would help those not very familiar with the framework
html would be helpful
0

Why don't you put a directive on each tab that has it's own controller? If you are using 1.x. Separate your code out by directive not tabs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.