简体   繁体   English

Angularjs-ui bootstrap.tabs-添加下一个选项卡按钮

[英]Angularjs-ui bootstrap.tabs - Adding Next tab button

I am using a modal to display a series of tabs using 我正在使用模态来显示一系列选项卡

<div class="modal fade hide modal-creator" data-backdrop="static" modal="imageUploader" tabindex="-1" data-focus-on="input:first">
<div class="modal-header">
    <h3>Create New Gallery</h3>
</div>
<div class="modal-body" id="imageUploader_sort">
    <tabset>
        <tab ng-repeat="tab in tabs" active="tab.active" heading="{{tab.title}}" disabled="tab.disabled" select="tabName(tab.title)">
            <div ng-include="tab.content"></div>
        </tab>
    </tabs>

</div><!-- /modal-body -->

<div class="modal-footer">
    <button ng-click="close()" class="btn" >Close</button>
    <button ng-click="next()" class="btn" >Next</button>
</div>

Controller 调节器

    $scope.tabs = [
        { title:"Home", content:"/beta/application/views/images/uploader/create.html", active: true },
        { title:"Upload", content:"/beta/application/views/images/uploader/upload.html"},
        { title:"Edit", content:"/beta/application/views/images/uploader/edit.html"}
    ];
$scope.next = function()
    {
        console.log($scope.tabs);
    };

I am looking to create a solution to navigate through the tabs with a next button and when I reach the last page, turn the button into a finished button. 我正在寻找一种解决方案,以使用下一个按钮浏览选项卡,当我到达最后一页时,将按钮变成完成按钮。 Any guidance on this a great help Thanks 任何对此有很大帮助的指导,谢谢

Here's a more complete answer that handles both direct navigation as well as clicking Next for the button state. 这是一个更完整的答案 ,既可以处理直接导航,也可以单击下一步以获取按钮状态。

Besides tracking the selected tab using the select attribute, I also changed the way the button is displayed, by splitting it into two buttons. 除了使用select属性跟踪选定的选项卡之外,我还通过将按钮分为两个按钮来更改按钮的显示方式。 This way the text is maintained within the view, and is independent of the model state. 这样,文本就可以在视图中维护,并且与模型状态无关。

<button ng-show="!isLastTab()" class="btn btn-small" ng-click="proceed()">Next</button>
<button ng-show="isLastTab()" class="btn btn-small" ng-click="proceed()">Finish</button>

The JS looks like this now: JS现在看起来像这样:

$scope.selectedTab = 0;

$scope.tabSelected = function(index) {
    $scope.selectedTab = index;
}

var isLastTab = function() {
    return $scope.selectedTab === $scope.tabs.length-1;
}

$scope.isLastTab = isLastTab;

$scope.proceed = function() {
    if(!isLastTab()){
        $scope.selectedTab++;
        $scope.tabs[$scope.selectedTab].active = true;
    }
};

This example should get you started down the right path. 这个例子应该使您正确地开始。

http://plnkr.co/edit/h2J9nBSYtEI7hwCz2Xp8?p=preview http://plnkr.co/edit/h2J9nBSYtEI7hwCz2Xp8?p=preview

angular.module('plunker', ['ui.bootstrap']);
var TabsDemoCtrl = function ($scope) {
  $scope.tabIndex = 0;
  $scope.buttonLabel = "Next";

  $scope.tabs = [
    { title:"Step 1", content:" content 1", active: true },
    { title:"Step 2", content:" content 2" },
    { title:"Step 3", content:" content 3" },
    { title:"Step 4", content:" content 4" }
  ];

  $scope.proceed = function() {
     if($scope.tabIndex !== $scope.tabs.length -1 ){
      $scope.tabs[$scope.tabIndex].active = false;
      $scope.tabIndex++
      $scope.tabs[$scope.tabIndex].active = true;
     }

     if($scope.tabIndex === $scope.tabs.length -1){
        $scope.buttonLabel = "Finish";
     }
  };

  $scope.setIndex = function($index){
      $scope.tabIndex = $index;
  };

};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM