1

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?

4 Answers 4

1

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

Comments

0

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.