我在與以下結構的模板(地址接觸-info.html裏):AngularJS:公開NG-重複範圍NG-transclude
<dd ng-repeat="contact in contactInfo | limitTo: displayedItems | orderBy:'desc'">
<span ng-transclude></span>
</dd>
而且一個指令:
{
templateUrl: 'address-contact-info.html',
restrict: 'A',
scope: {
contactInfo: '='
},
transclude: true,
link: function (scope, elem, attrs, ctrl, transclude) {
scope.displayedItems = 1;
}
};
我想用這樣的指令:
<div address-contact-info contact-info="tel">
<span>{{contact.number}}</span>
</div>
這意味着我要訪問我transcluded ELE內的NG-重複範圍但是我不知道該怎麼做。
你有什麼想法如何做到這一點,還是有更好的方法來做到這一點?
感謝您的幫助!
更新 這裏一個plunker:http://plnkr.co/edit/4DYEUhHAPuJOLyG9omCT
更新
我發現對我的作品,但我仍然有一個問題的解決方案。 我想在模板中跨越的元素有它們自己的指令,這些指令需要父指令。
現在,當我把我的linkFn內transcludeFn,我得到以下錯誤:
Error: [$compile:ctreq] Controller 'editableGroup', required by directive 'editable', can't be found!
http://plnkr.co/edit/zriVyS7MzheSI8jcYM5d
在這種plunker我還沒有包括其他指令,但我得到一個相關transcludeFb錯誤也是如此。
Cannot set property 'nodeValue' of undefined
你有一個這樣的運動員嗎? – 2015-02-23 15:35:48
你想要在指令模板而不是視圖中重複的任何原因? – isherwood 2015-02-23 15:37:50
是的,因爲在模板中不僅僅是重複。 – Sebastian 2015-02-23 16:03:55