Search code examples
javascriptangularjsmodel-view-controllerangularjs-ng-repeatng-bind-html

angular js ng-html inside ng-repeat won't work


I'm using AngularJS with a third party service that generates html responses. I want to use ng-repeat to render the HTML responses as a list, however Angular is not showing it

I've created this jsFiddle to demonstrate my issue.


Solution

  • Create a filter for trusting the content

    <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 "";
            };
        }
    ]);
    

    original answer https://stackoverflow.com/a/34783962/3769965

    working fiddle : https://jsfiddle.net/ebinmanuval/LL5mr7tw/1/