3

In AngularJS, how can I create a simple tabbed navigation (switching content as tab is clicked)?

HTML:

<ul class="tabbed-navi">
    <li class="active">
        <a href="#one">Nav One</a>
    </li>
    <li>
        <a href="#two">Nav Two</a>
    </li>
    <li>
        <a href="#three">Nav Three</a>
    </li>
</ul>

<div class="active">
    Content One
</div>
<div>
    Content Two
</div>
<div>
    Content Three
</div>

I am looking for a simple, beginner-friendly example, not "download these other things and then..."

Ben
  • 14,557
  • 16
  • 84
  • 127

2 Answers2

2

See the AngularJS home page, the "Create Components" section. That sample app defines two directives: pane and tabs.

For some additional explanation about how this works, see 'this' vs $scope in AngularJS controllers

Community
  • 1
  • 1
Mark Rajcok
  • 356,856
  • 113
  • 487
  • 490
1

Maybe something like this...

<ul class="tabbed-navi">
    <li class="active">
        <a href ng-click="option=1">Nav One</a>
    </li>
    <li>
        <a href ng-click="option=2">Nav Two</a>
    </li>
    <li>
        <a href ng-click="option=3">Nav Three</a>
    </li>
</ul>

<div ng-class="option==1? 'active':''">
    Content One
</div>
<div ng-class="option==2? 'active':''">
    Content Two
</div>
<div ng-class="option==3? 'active':''">
    Content Three
</div>
Aral Roca
  • 4,848
  • 7
  • 45
  • 77