Reputation: 373
I am a rookie in angularjs. I'm currently working on a page where i should display various forms inside tabs.I've worked on a code which activates the other tab on a button click.Heres the html
<!DOCTYPE html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="TabsDemoCtrl">
<uib-tabset vertical="true" type="pills">
<p>Select a tab by setting active binding to true:</p>
<p>
<button type="button" class="btn btn-default btn-sm" ng-click="tabs[0].active = true">Select second tab</button>
<button type="button" class="btn btn-default btn-sm" ng-click="tabs[1].active = true">Select third tab</button>
</p>
<uib-tab ng-repeat="tab in tabs" heading="{{tab.title}}" active ="tab.active" disable="tab.disabled">
{{tab.content}}
</uib-tab>
</uib-tabset>
<hr />
</div>
</body>
</html>
and here's the controller.js
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TabsDemoCtrl', function ($scope, $window) {
$scope.tabs = [
{ title:'Dynamic Title 1', content:'Dynamic content 1' },
{ title:'Dynamic Title 2', content:'Dynamic content 2'}
];
});
here's the plunker link..http://plnkr.co/edit/v23qWGzqbw3Y5o51KhHf?p=preview
what i need is to get the buttons inside the 'dynamic content' i.e when we click the button in tab1 content,it activates the other tab. I also have to include much other html elements too. What are the methods in which i can achieve this?
Upvotes: 1
Views: 6664
Reputation: 2008
In order to active another tab from current tab:You can try this:
<tabset>
<tab heading="First" ng-attr-active="firtTab">
<button ng-click="gotonext()">Go Next Tab</button>
</tab>
<tab heading="Second" ng-attr-active="secondTab">Content2</tab>
</tabset>
$scope.firstTab = true;
$scope.secondTab = false;
$scope.gotonext= function(){
$scope.firstTab = false;
$scope.secondTab = true;
}
Upvotes: 0
Reputation: 11586
Use the following code
<uib-tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disable="tab.disabled">
{{tab.content}}
<button type="button" class="btn btn-default btn-sm" ng-click="$parent.tabs[($index+1)%2].active = true">Toggle tab</button>
</uib-tab>
You can take this button either start of the content or end of the content. But not in middle using this approach.
Upvotes: 1
Reputation: 123
Please take a look at https://docs.angularjs.org/api/ng/directive/ngInclude.
In "tab.content" you should have template urls, and use them like it is described in angular docs.
<uib-tab ng-repeat="tab in tabs" heading="{{tab.title}}" active ="tab.active" disable="tab.disabled">
<div ng-include="tab.content"></div>
</uib-tab>
Upvotes: 1
Reputation: 451
For the tabs you can use ng-show directive,
<li ng-show="myScopeVar == 1">ALl your html here or use a directive</li>
<li ng-show="myScopeVar == 2">ALl your html here or use a directive</li>
<li ng-show="myScopeVar == 3">ALl your html here or use a directive</li>
if the $scope.myScopeVar == 2 then only the second li will be visible, the others will be invisible.
Upvotes: 0