是否可以将元素替换为ng-transclude
在它而不是整个模板元素上?
HTML:
<div my-transcluded-directive>
<div>{{someData}}</div>
</div>
指示:
return {
restrict:'A',
templateUrl:'templates/my-transcluded-directive.html',
transclude:true,
link:function(scope,element,attrs)
{
}
};
我的-transincluded-directive.html:
<div>
<div ng-transclude></div>
<div>I will not be touched.</div>
</div>
我正在寻找的是一种拥有的方式<div>{{someData}}</div>
代替<div ng-transclude></div>
。当前发生的情况是嵌入的 HTML 被放置inside the ng-transclude
div 元素。
那可能吗?
我认为最好的解决方案可能是创建您自己的嵌入替换指令来处理这个问题。但是,对于您的示例的快速而肮脏的解决方案,您基本上可以手动将嵌入的结果放置在您想要的位置:
我的-transincluded-directive.html:
<div>
<span>I WILL BE REPLACED</span>
<div>I will not be touched.</div>
</div>
指示:
return {
restrict:'A',
templateUrl:'templates/my-transcluded-directive.html',
transclude:true,
link:function(scope,element,attrs,ctrl, transclude)
{
element.find('span').replaceWith(transclude());
}
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)