【发布时间】:2017-07-17 00:39:36
【问题描述】:
我有一个指令,我正在用 img src 替换 IMG url 以显示内联图像
function message($filter) {
var directive = {
restrict: 'EA',
scope: {
data: '='
},
link: function(scope, elem, attrs) {
scope.data.content = scope.data.content.replace(/(https?:\/\/\S+(\.png|\.jpeg|\.jpg|\.gif))/g, "<img src='$1' alt=''>");
},
template: '<span>{{data.nickname}}:</span> {{data.content}}'
};
return directive;
}
但我没有看到内联图像,而是将 HTML 标记视为文本,我正在调查 $sce 但我不确定如何在指令中使用它。
【问题讨论】:
标签: javascript angularjs templates