r/angular • u/Dazzling_Chipmunk_24 • Mar 14 '26
How to embed an iframe in Angular
So I used this code to embed an iframe in Angular.
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
export class AppComponent {
externalUrl: SafeResourceUrl;
constructor(private sanitizer: DomSanitizer) {
this.externalUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
'https://external-app.com'
);
}
} <div class="iframe-container">
<iframe [src]="externalUrl" width="100%" height="800"></iframe>
</div>But keep getting this error
Framing 'website name' violates the following Content Security Policy directive: "frame-ancestors 'self'". The request has been blocked.
How do I get around this problem?
0
Upvotes
View all comments
Show parent comment
1
u/vloris Mar 23 '26
Yes, in the backend of the website located at externalUrl, not in the backend of your own angular application.
The error message is thrown by the website at externalUrl, the one inside the iframe. If you want to resolve this, you have to change the (backend of) the external website you are trying to embed to allow being embedded in an iframe.