是否可能以某种方式使用ngTransclude作为属性值,而不是替换内部的HTML内容?例如这个简单的指令
var testapp = angular.module('testapp',[]) testapp.directive('tag',function() { return { template: '<h1><a href="{{transcludeHere}}" ng-transclude></a></h1>',restrict: 'E',transclude: true } });
并使用它
<tag>foo</tag>
我想把它翻译成
<h1><a href="foo">foo</a></h1>
有什么办法做,或者我必须使用属性而不是转录?
这样的东西:
var testapp = angular.module('testapp',function() { return { restrict: 'E',template: '<h1><a href="{{transcluded_content}}">{{transcluded_content}}</a></h1>',replace: true,transclude: true,compile: function compile(tElement,tAttrs,transclude) { return { pre: function(scope) { transclude(scope,function(clone) { scope.transcluded_content = clone[0].textContent; }); } } } } });
原文地址:https://www.jb51.cc/angularjs/145293.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。