加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何用ng-transclude替换元素

发布时间:2020-12-17 08:42:23 所属栏目:安全 来源:网络整理
导读:是否可以用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,
是否可以用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)
    {

    }
};

my-transcluded-directive.html:

<div>
    <div ng-transclude></div>
    <div>I will not be touched.</div>
</div>

我正在寻找的是一种方式让< div> {{someData}}< / div>替换< divng-transclude>< / div&gt ;.当前发生的是被转换的HTML被放置在ng-transclude div元素内。 那可能吗?

我认为最好的解决方案可能是创建自己的transclude-replace指令,将处理这个。但是对于一个快速和肮脏的解决方案,你的例子你可以基本上手动放置你想要的互换的结果:

my-transcluded-directive.html:

<div>
    <span>I WILL BE REPLACED</span>
    <div>I will not be touched.</div>
</div>

指示:

return {
    restrict:'A',attrs,ctrl,transclude)
    {
         element.find('span').replaceWith(transclude());
    }
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读