21

I have a $scope variable like so:

$scope.example = "<h1>Hello</h1>"

When I output this in my view {{example}}, I want the HTML rendered. At the moment it outputs:

<h1>Hello</h1>

rather than

Hello

Is what I am trying to achieve possible?

0

1 Answer 1

33

It should be

$scope.html = "<h1>Hello</h1>";

and

<div ng-bind-html-unsafe="html"></div>

Also see this, AngularJS : Insert HTML into view

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

5 Comments

It is nice that you don't do the DOM manipulation like this but the above was answer to the question being asked.
You shouldn't put kerosene in your gas tank either but nothing is stopping you. If you want to do Angular you should do it correctly. Junk code leads to junk products.
What if you get a HTML-formatted blog article from a remote server where you cannot predefine any scopes? for me this solution worked: <p ng-bind-html="article.body"></p>
@redestructa spot on.
A bit outdated yet, but more info is given at your link. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.