0

I have this string which arrives from the server side.

  <iframe scrolling="no" frameborder="0" allowtransparency="true" height="250" width="300" style="border:0;" src="http://cdn.castplatform.com/scripts/au1324.html?subid=6e6c4c9092a4fd311393cd770c71ff05"></iframe&gt

I want to present the html rendered. When using $sce.trustAsHtml I get on the view:

<iframe scrolling="no" frameborder="0" allowtransparency="true" height="250" width="300" style="border:0;" src="http://cdn.castplatform.com/scripts/au1324.html?subid=6e6c4c9092a4fd311393cd770c71ff05"></iframe>

I would expect to get the html rendered (see picture) and not just the html stripped from the escape characters (as above):

html rendered as I would expected

What am I'm missing here? Here is the js code:

$scope.field_value = $sce.trustAsHtml($sanitize(field_value)); 

and the view code:

<div ng-bind-html="field_value"></div>

Thanks.

omer bach
  • 2,345
  • 5
  • 30
  • 46
  • if you send encoded value from server, then _trustAsHtml_ not helps, try send from server not encoded html – Grundy Nov 15 '15 at 13:12
  • This is not encoded, If I populate field_value with the string without escape characters : then it is fine. Seems that I need to do another trustAsHtml as the first one only renders the escape chacters – omer bach Nov 15 '15 at 13:44

1 Answers1

0

You need another decoding step (copied from https://stackoverflow.com/a/31290632/3563439):

app.filter('trusted', ['$sce', function($sce) {
    var div = document.createElement('div');
    return function(text) {
        div.innerHTML = text;
        return $sce.trustAsHtml(div.textContent);
    };

Fiddle: http://jsfiddle.net/masa671/8kphL7xe/

Community
  • 1
  • 1
masa
  • 2,762
  • 3
  • 21
  • 32