Nemanja Grabovac
Nemanja Grabovac

Reputation: 878

How to bind HTML to an Element - AngularJS

I am trying to bind html to my div element, but dont really know how to do it. I am not great with angularjs, but should ng-bind-html do the trick?

This is how I tried to do it,

<div ng-bind-html="{{tile.Info.Title}}"></div>
<div ng-bind-html="{{tile.Info.Content}}"></div>

In angular 2 its just [innerHTML], cant get it to work here, any suggestion?

Upvotes: 0

Views: 627

Answers (2)

Kannan Thangadurai
Kannan Thangadurai

Reputation: 1135

As also suggested in comments by @Aleksey when you are using ng- there is no need to use curly brackets {}. So your code should be like:

<div ng-bind-html="tile.Info.Title"></div>
<div ng-bind-html="tile.Info.Content"></div>

Upvotes: 1

Quan Vo
Quan Vo

Reputation: 1336

You can get an example here.

<div ng-controller="ExampleController">
 <p ng-bind-html="myHTML"></p>
</div>

Upvotes: 2

Related Questions