0

I want this piece of code

<test data="myObject"></test>

to be rendered as

<p>raw html code that is stored inside myObject.html</p>

My directive

module.directive('test', function() {
    return {
        restrict: 'E',
        template: '<p ng-bind-html="__what_to_do_here__?"></p>',
        scope: {
            // This object has a html propery which contains raw html.
            data: '='
        }
    };
});

How can i pass the raw html variable to the ngBindHtml directive in my template?

2
  • ng-bind-html="data.html" - does that work? Commented Feb 13, 2015 at 21:31
  • nope - that's why i'm asking Commented Feb 13, 2015 at 21:36

1 Answer 1

1

Did you include ngSanitize? I think it is required to be able to render html from a variable. You can find more information about ng-bind-html here: https://docs.angularjs.org/api/ng/directive/ngBindHtml (will also link you to ngSanitize)

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

1 Comment

Thanks for the replies, this is my first answer. And as I don't have enough reputation, I couldn't ask the question as a comment... Will try to make it better next time

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.