0

This is my filter in Angular, I've only shown the snippet of it the application. This works in one controller but when I try to use it in another one it doesn't.

What I mean by is doesn't work - it doesnt render inside the DOM. It renders inside the tags though.

AngularJS: <h2 ng-bind-html="'{{ answer.title }}' | to_trusted"></h2>

Example Rendered <h2 ng-bind-html="'0-60 minutes per week' | to_trusted" class="ng-binding"></h2>

AngularJS Filter

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

Have I missed something out by accident here?

3
  • Why are you using '' to wrap the {{}} ? Commented Dec 8, 2014 at 14:41
  • @OmriAharon because I receive Error: [$parse:syntax] http://errors.angularjs.org/1.2.18/$parse/syntax?p0=to_trusted&p1=is%20an%20unexpected%20token&p2=4&p3=%20%7C%20to_trusted&p4=to_trusted at Error (native) Error message Commented Dec 8, 2014 at 14:42
  • I believe my answer will address the issue Commented Dec 8, 2014 at 14:43

1 Answer 1

1

I think what will make it work for you is this syntax, since answer.title is text already:

<h2 ng-bind-html="answer.title | to_trusted"></h2>
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.