brazorf
brazorf

Reputation: 1961

AngularJS directive that contains ng-bind-html directive

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?

Upvotes: 0

Views: 56

Answers (1)

Hugues Stefanski
Hugues Stefanski

Reputation: 1182

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)

Upvotes: 1

Related Questions