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.

2
  • if you send encoded value from server, then trustAsHtml not helps, try send from server not encoded html Commented Nov 15, 2015 at 13:12
  • This is not encoded, If I populate field_value with the string without escape characters : <iframe scrolling="no" frameborder="0" allowtransparency="true" height="250" width="300" style="border:0;" src="cdn.castplatform.com/scripts/…> then it is fine. Seems that I need to do another trustAsHtml as the first one only renders the escape chacters Commented Nov 15, 2015 at 13:44

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.