【发布时间】:2017-01-22 08:10:03
【问题描述】:
我创建了一个名为 image-multiselect 的 angularjs 指令,可以按如下方式使用。
<image-multiselect items="landTransportTypes" image="illustrationURL" itemname="name" append="<div class='detail'>...some html here...</div>"></image-multiselect>
注意 append 属性,它被分配了一个 html 作为字符串。我希望使用这个 html 字符串来修改 DDO 中的 template 属性,如下所示
function(){
var imageMultiselect = function(){
return {
scope : {
items: "=",
image: "@",
itemname: "@",
append: "@"
},
template : "<div style='background:#f2f2f2;padding:20px;margin:20px;border-radius:5px;min-height:100px;'>" +
"<div ng-repeat='item in items' class='card text-center'>" +
"<img class='card-img' src='{{item[image]}}' alt='Avatar'>" +
"<div class='detail'>" +
"<b>{{item[itemname]}}</b>" +
/*append used to customize template as per requirement*/
"{{append}}"+
"</div>" +
"</div>" +
"</div>"
}
}
angular.module("myApp").directive("imageMultiselect",imageMultiselect);
}());
问题:在追加中传递的 html 字符串没有呈现为 html,而是整个标记显示在页面上?
【问题讨论】:
-
使用 ng-bind-html,否则不评估
标签: angularjs angularjs-directive