-2

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.

3
  • Did you even bother to write the full code? Or at least ng-app code? But you are expecting us to find out the issue? Commented May 9, 2016 at 5:27
  • Sorry thought that were a given. My ctrl is connecting if it outputs the whole string. Commented May 9, 2016 at 5:29
  • @VictorLe check my answer Commented May 9, 2016 at 5:33

4 Answers 4

1

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.

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

4 Comments

I was grabbing it from the database. So the data included the html tags
Ok, in that case please see my updated answer.
Thank you so much it works now. I thought i was going crazy that I couldn't figure this out.. lmfao.
Hehe, no problem. Glad to help!
1

Try this

<h1 ng-bind-html-unsafe="name"></h1>

Comments

0

Try This

<div ng-if="name" ng-bind-html="name"></div>

1 Comment

It doesn't spit out anything on the screen with this method
0
<b>
$scope.renderHtml = function(html_code)
{
    return $sce.trustAsHtml(html_code);
};
HTML:

<p ng-bind-html="renderHtml(value.button)"></p></b>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.