Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-ui tabs loading template in tab-content

I'm using the tabs in angular-ui using this controller:

$scope.panes = [
    { title:"Home",      content:"home" , active: true},
    { title:"Settings",  content:"settings"},
    { title:"View",      content:"view"}
];

and this in the html file:

<tabs>
    <pane
      active="pane.active"
      heading="{{pane.title}}"
      ng-repeat="pane in panes"
    >
      {{pane.content}}
    </pane>
  </tabs>

but i want to set the content as a template how can I do that, I tried setting the ng-include code in this plunker, but didn't work.
Thanks in advance.

update:

if you find this solution and you'r not using angular-bootstrap v0.12 you need to update the code to the new syntax of v0.13 like this:

<tabset>
    <tab
      active="pane.active"
      heading="{{pane.title}}"
      ng-repeat="pane in panes"
    >
      <div ng-include="pane.content"></div>
    </tab>
  </tabset>

I already updated the plunker to have the syntax of the angular-bootstrap v0.13.

like image 238
Yahya KACEM Avatar asked Feb 15 '13 13:02

Yahya KACEM


1 Answers

Just add the ng-include as a child of the pane

<tabs>
    <pane active="pane.active"
          heading="{{pane.title}}"
          ng-repeat="pane in panes">
        <div ng-include="pane.content"></div>
    </pane>
</tabs>

The reason this works is that the scope variable pane is not yet available when you use the ng-include in the same element as the ng-repeat that creates the pane variable.

This is because the priority value of the ng-include is 0(the default) while the priority of the ng-repeat is 1000 and so the order of execution is:

  1. ng-include
  2. ng-repeat

See the directive docs

like image 124
Liviu T. Avatar answered Oct 30 '22 19:10

Liviu T.