[英]Angular - Directive with dynamic template
我用动态模板创建了一个指令,它运行良好。 问题是我收到一个错误:
在Chrome = TypeError:undefined不是forEach.attr的函数
在Firefox = Error:element.setAttribute不是函数
这是代码:
return {
restrict:'E',
replace:true,
scope:{
content:'@'
},
controller:function($scope){
$scope.getTemplateUrl = function() {
if($scope.content.match(/<img/i) && !$scope.content.match(/icon-subs/i)) {
return 'app/templates/_image.html';
} else if ($scope.content.match(/<a/i)) {
return 'app/templates/_link.html';
} else if ($scope.content.match(/<iframe/i)) {
return 'app/templates/_video.html';
} else {
return 'app/templates/_minutes.html';
}
}
},
template: '<div ng-include="getTemplateUrl()"></div>'
};
指令标签:
<div ng-repeat="lance in contentsArray">
<icone-timeline data-content="{{lance.content}}"></icone-timeline>
<div ng-bind-html="lance.content"></div>
</div>
经过长时间的运行我找到了解决方案,问题是:
replace:true,
删除此部分后问题得以解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.