Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load html file into iframe in angular

Hi i am trying to load html file into iframe, but it is not working, If i load any external url it is working

in Component.ts

name = 'Set iframe source';
  url: string = "./add-cardIframe.component.html";
  urlSafe: SafeResourceUrl;

in oninit
ngOnInit() {
    this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
  }

HTML File:

<iframe width="100%" height="100%" frameBorder="0" [src]="urlSafe"></iframe>

getting error as Cannot match any routes. URL Segment: 'add-cardIframe.component.html' any help on this issue would be great

like image 687
Sudhir Avatar asked Apr 15 '26 21:04

Sudhir


1 Answers

Html:

<div [innerHTML]="html"></div>

TypeScript:

this.html = this.sanitizer.bypassSecurityTrustHtml(
      '<iframe width="100%" height="800" src="https://primefaces.org/primeng/#/"></iframe>',
    );
like image 95
Kuzenko Lubko Avatar answered Apr 18 '26 10:04

Kuzenko Lubko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!