is it possible to inject string into html's tag name with angular?
是否可以使用angular将字符串注入html的标记名称?
Something like this:
像这样的东西:
<div ng-repeat="type in types">
<bettype-{{type.id}}></bettype-{{type.id}}>
</div>
The output I need is:
我需要的输出是:
<bettype-1></bettype-1>
<bettype-2></bettype-2>
I am also using polymer (this way I am creating the custom html tags).
我也在使用聚合物(这种方式我正在创建自定义的html标签)。
2
I think the best solution would be to create a directive which creates custom elements, something like:
我认为最好的解决方案是创建一个创建自定义元素的指令,如:
.directive('bettype', function($compile) {
return {
restrict: 'E',
compile: function($element, $attr) {
return function($scope, $element, $attr) {
// Create new element here with $attr.number
var number = $attr.number,
element = angular.element('<bettype-'+number+'></bettype-'+number+'>');
// Replace newly created element
$element.replaceWith(element);
$compile($element)($scope);
}
}
}
});
Not sure if that will work, but probably that's the way to go...
不确定这是否会奏效,但可能就是这样......
Note: I don't think it\s a good idea to have dashed separated elements like bettype-1
..
注意:我不认为使用像bettype-1这样的虚线分隔元素是个好主意。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2014/06/19/60be41f671fda7af55ed70d7cf63c46a.html。