Blog Post

Angular render as html does not work - the solution

Friday, June 3, 2016 4:33 AM

I have been working with angular to render html using following html code


<div ng-bind-html-unsafe="{{preview_data}}"></div>



Instead of declaring a function in your scope, you can convert it to a simple filter :

    .filter('to_trusted', ['$sce', function($sce){
        return function(text) {
            return $sce.trustAsHtml(text);

Then you can use it like this :

<div ng-bind-html="preview_data.preview.embed.html | to_trusted"></div>

And here is a working example :