【问题标题】:angular js ng-html inside ng-repeat won't workng-repeat 中的 Angular js ng-html 不起作用
【发布时间】:2016-12-01 06:19:44
【问题描述】:

我将 AngularJS 与生成 html 响应的第三方服务一起使用。我想使用ng-repeat 将 HTML 响应呈现为列表,但是 Angular 没有显示它

我创建了这个jsFiddle 来演示我的问题。

【问题讨论】:

标签: javascript angularjs model-view-controller ng-repeat ng-bind-html


【解决方案1】:

为信任内容创建过滤器

<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/

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多