Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 7 linking with iframe

Tags:

angular

iframe

I'm trying to bind a link (project.projectUrl) inside an iframe but cannot seem to get it to work. I'm trying to bind the projectUrl from my JSON file to the iframe src so I can dynamically display iframes from within a modal if that is possible. Please see my code in the comment below.

like image 228
integral100x Avatar asked Nov 30 '22 08:11

integral100x


1 Answers

You need to sanitize the src. https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustResourceUrl.

One of the ways to do it, in your component constructor:

constructor(sanitizer: DomSanitizer, ....)

and then

<iframe [src]="sanitizer.bypassSecurityTrustResourceUrl(project.projectUrl)" height="600" width="1000"></iframe>

like image 139
avramz Avatar answered Jan 02 '23 02:01

avramz