简体   繁体   English

带有ng-repeat的角度ui-bootstrap:如果没有选项卡,则不会选择新选项卡

[英]Angular ui-bootstrap with ng-repeat: if there's no tabs, new tab isn't selected

Here's the link to demonstrate my problem: http://codepen.io/pietrofxq/pen/ZLLJdr?editors=1010 这是演示我的问题的链接: http : //codepen.io/pietrofxq/pen/ZLLJdr?editors=1010

Click in "remove tabs" and then in "add tab" 点击“删除标签”,然后点击“添加标签”

The issue: I do a loop with ng-repeat to display tabs. 问题:我使用ng-repeat循环显示标签。 But there may be a time when there's no items in the array, and when I add one tab back, I'd like this tab to come already selected, because it's the only one in the tabs array. 但是有时可能会出现数组中没有项目的情况,并且当我向后添加一个标签时,我希望此标签已被选中,因为它是tabs数组中唯一的标签。 The behavior now is that I have to click in the tab to angular to know that that tab is selected. 现在的行为是,我必须单击选项卡以使其成角度才能知道已选择该选项卡。 How can I make this tab selected when I add it in the array? 在数组中添加该选项卡时,如何选择它?

Found a dirty hack to make it work. 找到了一个肮脏的骇客使其正常工作。

I have more than one tab, so I need to keep track of each one: 我有多个标签,因此我需要跟踪每个标签:

$scope.tabs = {
  tabOne: 0,
  tabTwo: 0
}

<uib-tabset active="tabs.tabOne"></uib-tabset>
<uib-tabset active="tabs.tabTwo"></uib-tabset>

When the array is empty and I add one more tab, I have to reset the value inside a $timeout call: 当数组为空并且添加了另一个标签时,我必须在$ timeout调用中重置该值:

$scope.$watch("items", function() {
 $timeout(function() {
    for (var prop in $scope.tabs)
      $scope.tabs[prop] = 0 
  })
}

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

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