2

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
  • 343
  • 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

2

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
  • 78,495
  • 36
  • 155
  • 210
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()]
})
Cold Cerberus
  • 2,096
  • 2
  • 18
  • 42