我将AngularJS与生成html响应的第三方服务一起使用。我想使用ng-repeat
将HTML响应呈现为列表,但是Angular没有将其显示为
我创建了这个jsFiddle来演示我的问题。
创建一个用于信任内容的过滤器
<div ng-bind-html="myData | trustAs"></div>
angular.module('app').filter('trustAs', ['$sce',
function($sce) {
return function (input, type) {
if (typeof input === "string") {
return $sce.trustAs(type || 'html', input);
}
console.log("trustAs filter. Error. input isn't a string");
return "";
};
}
]);
原始答案https://stackoverflow.com/a/34783962/3769965
工作小提琴:https://jsfiddle.net/ebinmanuval/LL5mr7tw/1/