我有一個這樣的元素:Angularjs指令模板transclusion
<input test class="foo bar" ng-model="foo" name="foo"/>
而且我試圖把它變成像下面的例子中,當它具有「測試」屬性:
<div class="something">
<input type="text" class="foo bar" ng-model="foo" name="foo"/>
<span>test</span>
</div>
但是我有問題transclusion,而不是屬性被轉移到輸入端,他們得到轉移到div,所以我最終的東西,如:
<div class="something foo bar" type="text" ng-model="foo" name="foo">
<input/>
<span>test</span>
</div>
這裏的指令:
.directive('test', [function() {
return {
transclude:true,
replace:true,
template:'<div class="something">\
<input ng-transclude>\
<span>hi</span>\
</div>',
link: function (scope, element, attrs, ngModel) {
// do stuff
}
}
}])