问题
all.
I am using angular and ui-bootstrap to create a menu of tabs on which (hopefully) a user can enable/disable tabs that they do not need. I have tried to adhere pretty closely to the template code, as well as implementing my own functions to disable the tabs on click, but I haven't been able to get my tabs to respond the same way that they do in the example. I have been reading around and would guess that it has something to do with the ng-repeat creating its own scope, but I haven't solved it yet. Any help would be much appreciated!
I have tried to demonstrate what I am dealing with in this plunker.
Relevant controller code:
$scope.theirTabs = [
{ title:'Dynamic Title 1', content:'Dynamic content 1' },
{ title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
];
$scope.myTabs = [
{ title:'Orders',
content: {
description: 'DESCRIPTION',
poNumber: 'PO_NUMBER',
origFacility: 'ORIGIN_FACILITY',
destName: 'D_NAME',
destCity: 'D_CITY' ,
transitType: 'TRAN_TYPE',
transitCode: 'TRAN_CODE'
},
disabled: false
},
{ title:'Inventory',
content: {
createdDateTime: 'CREATED_DATE_TIME',
userName: 'USER_NAME'
},
disabled: false
},
{ title:'Items',
content: {
allocatedQty: 'ALLOCATED_QTY',
unitsPacked: 'UNITS_PAKD',
shippedQty: 'SHIPPED_QTY'
},
disabled: false
},
{ title:'Activity',
content: {
orderNumber: 'ORDER_NUMBER',
poNumber: 'PO_NUMBER',
origFacility: 'ORIGIN_FACILITY'
},
disabled: true
}
];
$scope.disableTab = function(tab, index) {
tab.disabled = true;
console.log('tab at index ' + index + ' should be disabled');
};
Relevant html (only mine included here):
<div class="row">
<div ng-repeat="tab in myTabs track by $index" class="select-tables-checkboxes col-md-3">
<!-- <label for="select-tables">{{tab.title}}</label> -->
<button type="button"
name="select-tables"
id="select-tables"
ng-click="myTabs[$index].disabled = ! myTabs[$index].disabled">Enable / Disable {{tab.title}}
<!-- also tried ng-click="disableTab(tab, $index)" -->
</div>
</div>
<tabset>
<tab ng-repeat="tab in myTabs" heading="{{tab.title}}" active="tab.active" ng-disabled="tab.disabled">
<!-- <div class="row" ng-repeat="(key, value) in content track by $index"></div> -->
<div class="row" ng-repeat="(k, v) in tab.content">
<div class="column-exists-checkbox col-md-1">
<input type="checkbox"
name="column-exists"
id="column-exists"
ng-model="columnExists">
</div>
<div class="column-description col-md-4">
<p class="column-description"><strong>{{k}}</strong></p>
</div>
<div class="column-name col-md-7">
<input type="text"
name="column-name"
id="column-name"
value="{{v}}">
</div>
</div>
<!-- </div> -->
</tab>
</tabset>
Incidentally, when I run my code and click my own buttons to disable/enable tabs (which I realize I've only coded to disable with the $scope.disableTab function), I am getting the correct console output, i.e. 'tab at index 0 should be disabled' when I click the Orders button, and so on.
Thank you in advance for any suggestions you may have!
回答1:
For the tab directive, you should be using the disable
attribute
<tab ng-repeat="tab in myTabs" heading="{{tab.title}}" active="tab.active" disable="tab.disabled">
来源:https://stackoverflow.com/questions/31374769/angular-ui-bootstrap-unable-to-disable-tabs-inside-ng-repeat