0

How to hide or show tabs according to user clicks in angularjs in ng-repeat.

this is my sample codepen in jquery it use

 $(this).attr

how can we do it in angularjs

1
  • 1
    ng-click and ng-show Commented Nov 25, 2016 at 10:36

3 Answers 3

1

If you'd like to code your own solution. On the collection add a property e.g. selectedItem and set that via ng-click on the tab header.

On the respective generated div you can then add a ng-show="item.$parent.selectedItem === item" to the respective div and you get a rather simple tab control.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use for tabs bootstrap ui library: https://angular-ui.github.io/bootstrap/#/top

On internet you can find another example for tabs. This is easy tutorial for tabs: https://thinkster.io/angular-tabs-directive

I hope I helped

Comments

0

You can use ng-template

template.html:

 <ul>
    <li ng-repeat="tab in tabs" 
        ng-class="{active:isActiveTab(tab.id)}" 
        ng-click="onClickTab(tab)">{{tab.title}}</li>
  </ul>
 <div id="mainView">
       <div ng-include="currentTab"></div>
    </div>
    <script type="text/ng-template" id="1.html">
      <!-- content for tab1 -->
    </script>
    <script type="text/ng-template" id="2.html">
      <!-- content for tab2 -->
    </script>

Contrller.js $scope.tabs = [{ title: 'One', id: '1.html' }, { title: 'Two', id: '2.html' }];

$scope.currentTab = '1.html';

$scope.onClickTab = function (tab) {
    $scope.currentTab = tab.id;
}

$scope.isActiveTab = function(tabUrl) {
    return tabUrl == $scope.currentTab;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.