0

I'm able to unescape the string that has some markup in it using ngSanitize and in HTML I use

<span ng-bind-html="myHTML"></span>

I've created a filter

.filter('safe', function($sce) {
    return function(val) {
      return $sce.trustAsHtml(val);
  };
})

I wonder if I can do something like this instead?

<span>{{ myHTML | safe }}</span>

Right now it does not really work and I'm trying to see what I'm missing.

2
  • Are you getting that "HTML not allowed" angular error? Commented Apr 9, 2014 at 0:41
  • No error at all except is just print like regular strings Commented Apr 9, 2014 at 1:13

1 Answer 1

2

You can make your own filter for that:

var app = angular.module('yourModuleName');
app.filter('safe', function($sce) {
    return function(htmlString) {
        return $sce.trustAsHtml(htmlString);
    }
};

Your markup would be something like:

<span ng-bind-html="myHTML | safe"></span>
Sign up to request clarification or add additional context in comments.

6 Comments

That's what I currently have but I'm looking for making it like example above
So, like if I don't use ng-bind-html is that possible to do so?
I really don't think so. {{ }} inside elements get evaluated and shown as strings (the element's text).
If you could, there would be no need for $sce, you could just place some html in a span and get it rendered...
True on that part except I'm injecting this from a JSON file :(
|

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.