【发布时间】:2015-05-05 03:32:00
【问题描述】:
如何实现 jQuery solution 使用 angular-bootstrap 的函数?我想实现播放按钮并打开从选中到最后一个标签的标签轮播。
var app = angular.module('app', ['ui.bootstrap']);
app.controller('homeCtrl', function($scope) {
$scope.tabs = [{
id: 1,
name: "Tab 1",
message: "",
active: true
}, {
id: 2,
name: "Tab 2",
message: "",
active: false
}, {
id: 3,
name: "Tab 3",
message: "",
active: false
}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<div ng-app="app">
<div ng-controller="homeCtrl">
<button class="btn btn-default"><i class="glyphicon glyphicon-play"></i>
</button>
<tabset>
<tab ng-repeat="tab in tabs" heading="{{tab.name}}" active="tab.active">
{{tab}}
</tab>
</tabset>
</div>
</div>
【问题讨论】:
-
为什么选择jQuery解决方案?您不想在控制器中编写事件处理程序吗?有什么具体原因吗?
-
@VinayK 链接已修复,我的意思是最好的方法是什么,控制器或指令或避免 jquery 并使用 jqLite?
-
这种情况下的最佳实践是编写指令。
-
我还提供了一个快速而肮脏的解决方案作为答案。
标签: javascript jquery angularjs twitter-bootstrap-3 angular-bootstrap