Alan2
Alan2

Reputation: 24562

Is there a simple way for me to include raw HTML from my model into a page with AngularJS?

I have raw HTML in my model.question.text I was looking at the following:

app.directive('ngHtml', function() {
    return function(scope, element, attrs) {
        scope.$watch(attrs.ngHtml, function(value) {
            element[0].innerHTML = value;
        });
    }
});

Can someone tell me if there is a simple way for me to include that in my page.

Upvotes: 2

Views: 45

Answers (1)

JB Nizet
JB Nizet

Reputation: 691645

I think you're looking for ngBindHtmlUnsafe:

Creates a binding that will innerHTML the result of evaluating the expression into the current element. The innerHTML-ed content will not be sanitized! You should use this directive only if ngBindHtml directive is too restrictive and when you absolutely trust the source of the content you are binding to.

See $sanitize docs for examples.

Upvotes: 3

Related Questions