當您使用NG-重複,它會創建一個新的範圍,它讓你NG-transclude不正確的範圍內用於注入transclusion。
所以,當你刪除ng-repeat時,你會得到渲染的組件。現在
,爲了控制佈局,您可以將元素添加到控制器,就像你與他們的範圍做,然後相應地佈局這些控制器:
// inside the controller
this.addComponentElement = function (componentElement) {
componentElements.push(componentElement);
};
// watch for array changes and handle layout
或者,你可以使用在編譯+鏈接組合transclude功能才能到transcluded DOM參考,並操縱它的佈局:
compile:function(telement, tAttrs, transcludeFn){
return function(scope, element, attrs){
transcludeFn(scope, function(transcludedDom){
// layout the transcludedDom
})
}
D'哦,回頭看的UI引導代碼,他們的確有外部的ngTransclude指令其循環(他們只是使用ngRepeat directiv e顯示每個窗格上方的選項卡列表)。謝謝您的幫助! – Monkey34 2013-05-03 23:37:33