angularjs - 如何判断在 Angular-UI 中选择了哪个 Bootstrap 选项卡

标签 angularjs twitter-bootstrap angular-ui angular-ui-bootstrap bootstrap-tabs

有没有办法知道使用 Angular UI 中的 Bootstrap 选项卡时选择了哪个选项卡?

我尝试查看 Pane 数组,但切换选项卡时它似乎没有更新。可以指定选项卡被选中时的回调函数吗?

更新代码示例。

该代码非常遵循 Angular UI Bootstrap 页面中的示例。

标记:

<div ng-controller="TabsDemoCtrl">
    <tabs>
        <pane ng-repeat="pane in panes" heading="{{pane.title}}" active="pane.active">
            <div ng-include="pane.template"></div>
        </pane>
    </tabs>
</div>

Controller :

var TabsCtrl = function ($scope) {
  $scope.panes = [
    { title:"Events list", template:"/path/to/template/events" },
    { title:"Calendar", template:"/path/to/template/calendar" }
  ];
};

最佳答案

实际上这非常简单,因为每个pane都公开支持2路数据绑定(bind)的active属性:

<tabs>
    <pane ng-repeat="pane in panes" heading="{{pane.title}}" active="pane.active">      
        {{pane.content}}
    </pane>
</tabs>

然后可以轻松找到事件选项卡,例如:

$scope.active = function() {
    return $scope.panes.filter(function(pane){
      return pane.active;
    })[0];
};

这是一个工作 plunk

关于angularjs - 如何判断在 Angular-UI 中选择了哪个 Bootstrap 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15685360/

相关文章:

javascript - 阻止动态 Bootstrap 词缀 div 超出页脚

html - 类 ="active"在 bootstrap 3 中到底做了什么?

javascript - Angular Js - 复选框模型未在 ng-change 上切换?

javascript - 带有 angularJS 的水平日计划器/调度器(拖放)

javascript - AngularJS 在 Html Table 上观看

html - 是否可以在表单提交按钮中使用 Glychicons?

javascript - 使用 ng-options 创建下拉菜单

javascript - 在 angular bootstrap ui typeahead 指令上触发按键事件

javascript - 我需要一个技巧来模拟标签上的插入符号

javascript - 在 if 语句中调用函数时的 Jasmine 测试用例