Chris Tarasovs
Chris Tarasovs

Reputation: 695

Angular2 : Inject HTML from an array and render the view

I building a basic drag and drop that has various prepared HTML that you can drag and drop into the page.

I got a object with the list of HTML that you can drag

element=[
 text: {html: '<p> asdasdasdas</p>'},
 list: {html: '<ul><li></li></ul>'};
 img: {html: '<img src="placeholder.jpg"/>'}
]

How to inject the html into the page?

Or should I be creating the HTML snippets as component and than having a referenced in the elements object to the component selector and injecting the angular selector and rendering the view?

Upvotes: 0

Views: 752

Answers (1)

Amadou Beye
Amadou Beye

Reputation: 2828

You can use ng-bind-html to bind html

<div ng-bind-html="element.text.html"></div>
<div ng-bind-html="element.list.html"></div>
<div ng-bind-html="element.img.html"></div>

Notice: You have to include ngSanitize module on your app in order to use ng-bind-html

Upvotes: 1

Related Questions