2

I'm working on some Bootstrap-UI tabs, but I can't find an instance online that uses templateURL without manipulating the URL of the page. Here's what I'd like to do:

HTML

<uib-tabset active="active">
    <uib-tab ng-repeat="tab in model.tabs" index="$index" heading="{{tab.title}}">
        {{tab.content}}
    </uib-tab>
</uib-tabset>

JS

model.jo = {...} // a gigantic JSON object - needs to be available in the templates.
model.tabs = [
    {
        title: "Visualized",
        content: url('vis.html')
    },
    {
        title: "Pure JSON",
        content: url('json.html')
    }
]

Most of the stuff I found online uses $routeProvider & $locationProvider to doctor up the URL in order to show different tabs, like this one: http://embed.plnkr.co/TMN3KNlS4Dv90SvbTQKJ/. I don't want to do that.

Is there any way to just define the templateUrl like you'd do for a component?

Also, I need my JSON Object, model.jo, in the html pages.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Travis Heeter
  • 13,002
  • 13
  • 87
  • 129

1 Answers1

8

You could use ng-include to render template by using its template URL. The only thing you need to change in your tabs object is, have templateUrl instead of content property.

<uib-tabset active="active">
    <uib-tab ng-repeat="tab in model.tabs" index="$index" heading="{{tab.title}}">
        <div ng-include="tab.templateUrl"></div>
    </uib-tab>
</uib-tabset>

Change tabs object to

model.tabs = [
    {
        title: "Visualized",
        templateUrl: 'vis.html'
    },
    {
        title: "Pure JSON",
        templateUrl: 'json.html'
    }
]

Also, ng-include uses the same controller as the source, so you will be able to access the model, specifically model.jo, in both of those pages. Source: Pass parameter to Angular ng-include

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • Cool, how could I send my data to those files? I have a big JSON object that needs to be available. – Travis Heeter Oct 26 '16 at 14:08
  • OK, found out that ng-include uses the same controller it's coming from. Source: http://stackoverflow.com/questions/25565475/pass-parameter-to-angular-ng-include Also, I tested it and it works. – Travis Heeter Oct 26 '16 at 14:21
  • Thanks, initially didn't work for me with :
    but worked with :
    . Notice the single quotes missing in the first one. Maybe this comment helps someone.
    – Ryan Augustine Feb 25 '19 at 07:33