-1

Lets say I have the below HTML Template whats the best way to assign it to a variable in Angular Project

public template = '<html><body> <p>This is a p tag</p>

     </body></html>'

How do I make such kind of assignment in typescript?

Jay
  • 2,485
  • 6
  • 28
  • 34

2 Answers2

0
public template = '<p>This is a p tag</p>'

In the Html

<div [innerHtml]="template"></div>
saidutt
  • 289
  • 1
  • 7
  • if its a big html template how can we include it in a new file and assign it to a variable? – Jay May 21 '19 at 20:14
0

If you have a project that work with Angular 7.^, you can use a binding with

<div [innerHtml]='template"></div>

Where template is declared in component like

template = '</p>This is a p ta</p>'

If your version is older then 7 you must sanitize your bindig with

<div [innerHTML]="template | safeHtml"></div>

Anyway, why declare a variables public if is the default value?

Shifenis
  • 1,056
  • 11
  • 22