Angularjs bootstrap tabset tab heading
Asked Answered
B

5

23

I am wondering whether it is possible to write html inside an angularjs bootstrap tabset tab heading. I am trying to add a svg inside the title. I have created a quick snippet in plunker to try and demonstrate the issue I am having.

<tabset>
  <tab heading="<span>hello</span><em>1</em>">One</tab>
  <tab heading="Two">Two</tab>
  <tab heading="Three">Three</tab>
</tabset>

http://plnkr.co/edit/qFsFGDNUIJj9nIF51ApU

any ideas?

thanks

Bloodworth answered 29/9, 2014 at 14:21 Comment(0)
D
47

Angular Bootstrap v0.14+

Angular Bootstrap v0.14 introduced new prefixes for most previously provided controls. The original answer below still applies, but you must use the new tag names uib-tabset, uib-tab, and uib-tab-heading.

<uib-tabset>
  <uib-tab>
    <uib-tab-heading>
      <span>hello</span><em>1</em>
    </uib-tab-heading>
    One
  </uib-tab>
  <uib-tab heading="Two">Two</uib-tab>
  <uib-tab heading="Three">Three</uib-tab>
</uib-tabset>

Angular Bootstrap < v0.14

You should be using the tab-heading element within the tab element if you want HTML within the heading (as shown in the example in the docs):

<tabset>
  <tab>
    <tab-heading>
      <span>hello</span><em>1</em>
    </tab-heading>
    One
  </tab>
  <tab heading="Two">Two</tab>
  <tab heading="Three">Three</tab>
</tabset>

Updated plunker here.

Denicedenie answered 29/9, 2014 at 19:47 Comment(1)
Bare in mind that if you're trying to get this to work in IE8 then you need to use attributes rather than elements. So: <div tabset><div tab><div tab-heading><span>hello</span></div></div></div>Pulsar
S
5

Since 2016

The accepted answer is ok for the ui-bootstrap prior version 0.14.0, since version 0.14.0 (2015.10.09) tabs use uib- prefix.

See changelog

So you have to replace all tags with uib- prefix

<uib-tabset>
  <uib-tab>
    <uib-tab-heading>
      <span>hello</span><em>1</em>
    </uib-tab-heading>
    One
  </uib-tab>
  <uib-tab heading="Two">Two</uib-tab>
  <uib-tab heading="Three">Three</uib-tab>
</uib-tabset>
Supertanker answered 24/10, 2016 at 7:19 Comment(0)
M
0

[edit] Taylor Buchanan's answer is the correct answer!

Looking at the template used by the tabs directive, the headings content will be escaped: https://github.com/angular-ui/bootstrap/blob/192768e109b5c4a50c7dcd320e09d05fedd4298a/template/tabs/tab.html#L2

So it is not possible to use html in your headings.


You can create a work-around by re-defining the tab template like so:

angular.module("template/tabs/tab.html").run(["$templateCache", function($templateCache) {
  $templateCache.put("template/tabs/tab.html",
    "<li ng-class=\"{active: active, disabled: disabled}\">\n" +
    "  <a ng-click=\"select()\" tab-heading-transclude ng-bind-html=\"heading\"></a>\n" +
    "</li>\n" +
    "");
}]);

You will also need to nclude angular-sanitize.js to safely bind html contents.

Working Demo here: http://plnkr.co/edit/ep5f1GY12vSixT4xtxFy?p=preview

Mordancy answered 29/9, 2014 at 15:3 Comment(1)
Thanks for looking at this. I will give this is a shot and let you know the results.Bloodworth
B
0

You can give your TAB tag an id and then use jQuery to augment the html.
...tab id="myid"....

and then jQuery("#myid").html("New Html")

Bankbook answered 29/9, 2014 at 17:58 Comment(1)
This is not in line with "The Angular Way". See #14994891Octopod
B
-1

            <li heading="Status" class="ng-isolate-scope var" ng-model="(var = 'active: active')" >
                <a href="/ibox">Status1</a>
            </li>


            <li heading="Status" class="ng-isolate-scope var" ng-model="var = 'active: active'">
                <a href="/netapp">Status</a>
            </li>


    </tabset>
Basque answered 29/4, 2015 at 18:22 Comment(1)
Code only answers are discouraged. Additionally, this does not attempt to answer the question.Denicedenie

© 2022 - 2024 — McMap. All rights reserved.