我正在尝试从第一个指令模板中应用的不同内部指令中访问元素指令中的已转换元素。 / p>
.directive('elementDirective', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
templateUrl: 'template.html',
link: function (scope, elem, attr, ctrl, transclude) {
elem.find('transclusion').replaceWith(transclude());
}
};
})
<div inner-directive>
<div id="transclusion"></div>
</div>
.directive('innerDirective', function() {
return {
restrict: 'A',
link: function (scope, elem, attr, ctrl) {
//Do something here with child elements (which will be transcluded).
var some = elem[0].querySelector('[name]');
//...
}
};
})
<element-directive>
<input name="input_name" />
</element-directive>
我收到了那种错误。
element-directive element has no child input elements with a 'name' attribute
我假设这意味着内部指令在转换发生之前被编译,链接,诸如此类,。那么,我怎样才能实现我的目标呢?