VictorLe VictorLe - 6 months ago 13
HTML Question

Html isn't recognizing the tags that Angularjs spitting out

Angular

$scope.name = "<h1>John Doe</h1>"


HTML

<div>{{name}}</div>


Outputs:

<h1>John Doe</h1>


How do I make it so Html recognize the tags that I'm spitting on the page.

Answer

The correct way would be:

$scope.name = 'John Doe';

HTML:

<div><h1>{{name}}</h1></div>

I don't know why would you set html tags in your variables if you really really don't need to.

EDIT according to comment:

In the case you need to use html tags in your templates, please see this answer on SO: AngularJS : Insert HTML into view

I'm not going to duplicate the answer because it's explained very well in that answer.