Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Elliott Frisch, EdChum, Jay Blanchard, Zach Saucier, sgress454 May 8 '14 at 22:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

It should be

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

and

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

Also see this, Insert HTML into view using AngularJS

share|improve this answer
    
I don't care what could be done to make it work, that's just plain bad code. Do any and all DOM manipulations in a directive. –  mortsahl May 8 '14 at 22:36
    
It is nice that you don't do the DOM manipulation like this but the above was answer to the question being asked. –  user1415567 May 9 '14 at 15:15
1  
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. –  mortsahl May 9 '14 at 16:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.