1

I've HTML string coming from API and inside HTML String I am getting youtube video into <iFrame></iFrame>

I want to display this video along with HTML.

export class BlogDetailsPage implements OnInit {
  detail = {};
  constructor(public domSanitizer: DomSanitizer, private ms: MasterService) { }

  ngOnInit() {
    var id = this.route.snapshot.params.id;
    this.ms.present();
    this.ms.getblogDetail(id).subscribe(res => {
      this.detail = this.domSanitizer.bypassSecurityTrustResourceUrl(res.content.rendered);
      console.log(this.detail);
      this.ms.dismiss();
    });
  }
}

In HTML I display string by following code

{{detail}}
<div class="blog-box" *ngIf="detail.content != undefined" [innerHTML]="detail">
</div>

Output enter image description here

I am unable to display HTML either Video.

Community
  • 1
  • 1
Ubiquitous Developers
  • 3,637
  • 6
  • 33
  • 78

1 Answers1

0

This is kind of a comment / guess but I needed the formatting and space to explain.

What I meant was remove the {{detail}} because I think that is causing your error.

Also, now I type this, it seems like you are using two different structures - detail.content in the if and then trying to display detail in the innerHTML.

Combining both of these ideas, try changing from this:

{{detail}}
<div class="blog-box" *ngIf="detail.content != undefined" [innerHTML]="detail">
</div>

To this:

<div class="blog-box" *ngIf="detail.content != undefined" [innerHTML]="detail.content">
</div>
rtpHarry
  • 13,019
  • 4
  • 43
  • 64