如何显示bootstrap模态选项卡的内容?

时间:2017-08-28 12:38:27

标签: javascript angularjs

我是AngularJS的初学者,我有一个带有2个标签的bootstarp模式我一次只显示一个标签。在模态中我有两个按钮NEXT和PREVIOUS我可以在标签之间切换通过这些按钮。但问题是当我更改标签时,各自标签中的内容不会改变。我哪里出错了。请帮助我。

<div class="modal-body">
<div role="tabpanel">
    <!-- Nav tabs -->
    <ul class="nav nav-tabs">
        <li class="active">
            <a href="#tab1" data-toggle="tab">
                <div>{{current.data}}</div>
            </a>
        </li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1">
            <textarea class="form-control" ng-model="first" name="first" required></textarea>
            <md-button class="md-raised md-primary" ng-click="next()">next</md-button>
            <md-button class="md-warn md-raised" ng-click="previous()">previous</md-button>
        </div>
        <div class="tab-pane" id="tab2">
            <textarea class="form-control" ng-model="second" name="second" required></textarea>
            <md-button class="md-raised md-primary" ng-click="next()">next</md-button>
            <md-button class="md-warn md-raised" ng-click="previous()">previous</md-button>
        </div>
    </div>
</div>

  

Controller.js

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
         $scope.dataSet = [
              { data: "First", index: 0 },
              { data: "Second", index: 1 }   
         ],
         $scope.current = $scope.dataSet[0],
         $scope.next = function() {
             var i = $scope.getIndex($scope.current.index, 1);
             $scope.current = $scope.dataSet[i];
         },
         $scope.previous = function() {
             var i = $scope.getIndex($scope.current.index, -1);
             $scope.current = $scope.dataSet[i];
         },
         $scope.getIndex = function(currentIndex, shift) {
             var len = $scope.dataSet.length;
             return (((currentIndex + shift) + len) % len)
         }
});

1 个答案:

答案 0 :(得分:1)

我已使用所选数据的ng-class属性更新了您的代码,请参阅https://jsfiddle.net/jasonantho/fwowg8q5/