I have three tabs in my page. I'm using tabset
and tab
according to Angular Bootstrap Docs.
I set a controller for the <div>
which has the tabset
as
<div ng-controller="Tabs" class="panel panel-default" id="tabs-panel">
<tabset class="panel-body">
<tab heading="Tab 1"> </tab>
<tab heading="Tab 2"> </tab>
<tab heading="Tab 3"> </tab>
</tabset>
</div>
But, when I try to add another controller for my 2nd tab as
<div ng-controller="Tabs" class="panel panel-default" id="tabs-panel">
<tabset class="panel-body">
<tab heading="Tab 1"> </tab>
<tab heading="Tab 2" ng-controller="Tab2> </tab>
<tab heading="Tab 3"> </tab>
</tabset>
</div>
I now find that the heading is not displayed and I can no longer click the Tab2.
Why is that? How to get back the same functionality?
Is this the right way to add another controller in an existing controller?
My app.js :
var myApp = angular.module('myApp',['ui.bootstrap']);
myApp.controller('Tabs', function ($scope) {
});
myApp.controller('Tab2', function ($scope) {
});
Here a custom directive to use in tabs, so I can use custom controllers for each tab.
I think there are at least three ways you could organize your controller code:
TabController
Please have a look at the demo below or here at jsfiddle.
It's the
ui-bootstrap
example code with the above mentioned points added.