如何以编程方式在Angular UI上选择选项卡?

时间:2016-08-04 19:08:15

标签: angularjs angular-ui

In this plunk我有三个从数组创建的选项卡。当我点击按钮时,我需要选择名为“名称1”的按钮并具有焦点。如何实现这一目标?

HTML

<uib-tabset>
   <uib-tab ng-repeat="t in tabs" heading="{{t.title}}" >
     {{t.content}}
   </uib-tab>
</uib-tabset>


<br/><br/><br/>
<button ng-click="tabs.select(1)">Focus on Name 1</button>

的Javascript

  $scope.tabs = [
    { title:'Name 0', content: "Content 0" },
    { title:'Name 1', content: "Content 1" },
    { title:'Name 2', content: "Content 2" }
  ];

1 个答案:

答案 0 :(得分:4)

您必须设置active 属性,如下所示:

<uib-tabset active="active">

然后在你的按钮中:

<button ng-click="active = 1">Focus on Name 1</button>

这是分叉的Plunker