Source Code

Dynamic Content in Dynamic Tab in Angularjs

Dynamic, flexible and accessible AngularJS tabs

Easy to use and customize,Keyboard accessible,Works with (or without) ng-repeat


Active index: {{ activeTabIndex }}
Tab count: {{ tabs.length }}
Some content

Example : index.html


 <!doctype html>
    <html ng-app="ui.bootstrap.demo">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
        <script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.2.4.js"></script>
        <link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body>
        <div ng-controller="TabsDemoCtrl">
            
            Active index: {{ activeTabIndex  }} <br /> Tab count: {{ tabs.length }} <br />
            
            <input type="button" value="Add Tab" ng-click="addTab()" />
            
            <uib-tabset active="activeTabIndex">
                <uib-tab ng-repeat="tab in tabs" heading="{{tab.title}}">Some content</uib-tab>
            </uib-tabset>
        </div>
    </body>
    </html>

Example : App.js


angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function($scope, $window, $timeout) {
  $scope.activeTabIndex = 0
  $scope.tabs = [];

  $scope.addTab = function() {
	var newTab = {  title: 'Tab ' + ($scope.tabs.length + 1) };
	$scope.tabs.push(newTab); 
	$timeout(function(){
	  $scope.activeTabIndex = ($scope.tabs.length - 1);
	});
	console.log($scope.activeTabIndex);
  };
});