我最終修補了ui-bootstrap文件。 我仍然是AngularJS的小菜鳥,所以請原諒這個術語。 這是一個非常規的黑客攻擊,需要用ng-animate重構,但它很有效。
開放UI的自舉TPLS-0.10.0.js並查找 '選項卡' 指令:
.directive('tab', ['$parse', function($parse) {
return {
require: '^tabset',
restrict: 'EA',
replace: true,
templateUrl: 'template/tabs/tab.html',
transclude: true,
scope: {
id:'@', // PATCH : GETTING TAB 'id' ATTRIBUTE
heading: '@',
onSelect: '&select', //This callback is called in contentHeadingTransclude
//once it inserts the tab's content into the dom
onDeselect: '&deselect'
},
// ...
通知檢索ID中的額外的代碼屬性值(通過transclusion,我猜)。
下面幾行,尋找:
scope.$watch('active', function(active) {
,並修補它,像這樣:
scope.$watch('active', function(active) {
// Note this watcher also initializes and assigns scope.active to the
// attrs.active expression.
setActive(scope.$parent, active);
if (active) {
tabsetCtrl.select(scope);
scope.onSelect();
tab_id = attrs.id;
$(".tab_pane_"+tab_id).hide(); // HIDE AT FIRST, SO IT CAN ACTUALLY FADE IN
$(".tab_pane_"+tab_id).fadeIn(1000); // JQUERY TARGETING BY CLASS
} else {
scope.onDeselect();
tab_id = attrs.id;
$(".tab_pane_"+tab_id).hide(); // JQUERY TARGETING BY CLASS
}
});
下方的幾行字,看爲:
scope.select = function() {
,往其中加:
$(".tab-pane").hide();
因此,所有標籤面板起初正常隱藏。
然後,查找:
angular.module("template/tabs/tabset.html", []).run(["$templateCache", function($templateCache) { ...
和CSS類添加到選項卡窗格元素在相應的模板,比如:
angular.module("template/tabs/tabset.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("template/tabs/tabset.html",
"\n" +
"<div class=\"tabbable\">\n" +
" <ul class=\"nav {{type && 'nav-' + type}}\" ng-class=\"{'nav-stacked': vertical, 'nav-justified': justified}\" ng-transclude></ul>\n" +
" <div class=\"tab-content\">\n" +
" <div class=\"tab-pane tab_pane_{{tab.id}}\" \n" + // CLASS NAME IS DYNAMIC
" ng-repeat=\"tab in tabs\" \n" +
" ng-class=\"{active: tab.active}\"\n" +
" tab-content-transclude=\"tab\">\n" +
" </div>\n" +
" </div>\n" +
"</div>\n" +
"");
}]);
一旦ui-bootstrap。js文件被修改,你必須編輯視圖模板(你取標籤),並宣佈了「id」屬性:
<!-- TABS -->
<tabset justified="true">
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" id="{{tab.id}}" >
// ... TAB CONTENT
你應該得到的基本概念,目前這不是很優雅(以溫和地說)。 但它的工作。
如果你想知道我的標籤是如何得到的id,好了,我注入他們在我的控制器:
Tab1 = {
id:1,
'ShortDescription': ShortDescription,
'FullDescription': FullDescription,
'TabContent': TabContent1,
title: "ProductTabTitleDefault1",
// active:true
};
Tab2 = {
id:2,
'ShortDescription': ShortDescription,
'FullDescription': FullDescription,
'TabContent': TabContent1,
title: "ProductTabTitleDefault2",
// active:true
};
$rootScope.tabs = {
'Tab1': Tab1,
'Tab2': Tab2,
};
當然,這是模型數據,但假設你的標籤和它們的內容是動態的,可以使用一個計數器,也許使用另一個鍵而不是「ID」(但你必須相應地改變其餘的)。
嘗試閱讀$ animate的文檔 - 也許它會給你一些想法。 – lort
我會......我希望有一些我忽略的快速解決方案,就像bootstrap3 js一樣,這很容易做到 – urish