4

I've a component and it has a ts file it contains html content as a variable.

para1= <a href="www.google.com">sitename</a> more content

I need to bind this paragraph in html like a html itself.

sitename

How can i achieve this?

coding_Lover
  • 393
  • 1
  • 4
  • 13
  • 1
    Possible duplicate of [Angular HTML binding](https://stackoverflow.com/questions/31548311/angular-html-binding) – veben Dec 12 '18 at 07:25

2 Answers2

4

Simply use innerHTML in case your variable value contains HTML template.

Like this -

para1= "<a href="www.google.com">sitename</a> more content"

In html file -

<span [innerHTML]='para1'></span>
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
0

You can use ngx-dynamic-template to achieve this.

In your example where para1= '<a href="www.google.com">sitename</a> . . .', you may have something like this:

<ng-template 
    dynamic-template
    [template]="para1"
>
</ng-template>

Don't forget your import:

import { NgxDynamicTemplateModule } from 'ngx-dynamic-template';

@NgModule({
    imports: [NgxDynamicTemplateModule.forRoot()]
})
Alex Pappas
  • 2,377
  • 3
  • 24
  • 48