Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular UI Bootstrap tabset + ng-include

I have trouble setting up a tabset with dynamic contents using ng-include. I tried unsuccessfully with ng-repeat :

<tabset justified="true">
    <tab ng-repeat="tab in tabs" heading="{{ tab.heading }}" active="tab.active">
         <div ng-include="tab.template"></div>
    </tab>
</tabset>

Also, I tried without the ng-repeat :

<tabset justified="true">
    <tab heading="{{ tabs.1.heading }}" active="tabs.1.active">
         <div ng-include="'partial/profile/template1.html'"></div>
    </tab>
    <tab heading="{{ tabs.2.heading }}" active="tabs.2.active">
         <div ng-include="'partial/profile/template2.html'"></div>
    </tab>
    <tab heading="{{ tabs.3.heading }}" active="tabs.3.active">
         <div ng-include="'partial/profile/template3.html'"></div>
    </tab>
    <tab heading="{{ tabs.4.heading }}" active="tabs.4.active">
         <div ng-include="'partial/profile/template4.html'"></div>
    </tab>
    <tab heading="{{ tabs.5.heading }}" active="tabs.5.active">
         <div ng-include="'partial/profile/template5.html'"></div>
    </tab>
</tabset>

Yet, what I get is a blanck page, not responding and those errors :

WARNING: Tried to load angular more than once.

and

10 $digest() iterations reached. Aborting!

FYI: the templates are mainly empty, the one not empty contain a basic table. How am I to make it work ?

like image 335
Romain Avatar asked Oct 21 '14 15:10

Romain


People also ask

How to make a tab using angular UI bootstrap?

Angular UI Bootstrap is an Angular JS framework created by Angular UI developers for providing better UI which can be used easily. First, add Angular UI bootstrap scripts needed for your project. Make tab with its UIBootStrap classes which will set the UI look for the tab.

Why use ng-bootstrap components?

Bootstrap components are getting used for a long time by developers to add multi-device and screen support. So using ng-bootstrap components not only fasten the development process but also adds up responsive behavior to these components by default.

How to handle tab change event in NGB-tab component?

The tabChange output property event can be handled in component by importing NgbTabChangeEvent to get tab properties as shown below: The ngb-tab component is used to create a tab in Tabset. title: String value for tab title. Custom HTML content can be added for Tab title and its content using ngbTabTitle and ngbTabContent component directive.

What is the NGB-tabset?

The ngb-tabset is the main wrapper for Tabset tabs. destroyOnHide: Default is true. The non-visible tabs will be removed from DOM. justify: The horizontal arrangement of tabs can have any of these types: "start" | "center" | "end" | "fill" | "justified"


1 Answers

Looks like you had extra quotes when using ng-repeat. The extra quotes in ng-include="'x.html'" are only needed if it's used as an attribute.

When specifying it as a variable in JavaScript, you set the scope variable in JavaScript as follows: $scope.someTemplateUrl = "x.html"; then set the attribute to ng-include="someTemplateUrl". Notice the value of the variable doesn't contain the single quotes.

And the second version you should be doing tab[0].heading rather than tab.0.heading (and starting from 0 rather than 1).

I've created a Plunker containing a working version and it seems to work correctly:

http://plnkr.co/edit/cL9RPB4otw57pORJqjvx?p=preview

What I did:

  • removed the extra quotes from the template property
  • removed html5Mode because Plunker doesn't work with that.

So something like:

$scope.tabs = [
        {
            "heading": "Tab 1",
            "active": true,
            "template":"tab1.html"
        },
        ...
like image 192
sirhc Avatar answered Oct 31 '22 08:10

sirhc