While this question may be old, the solution provided could still benefit many individuals.
To achieve this functionality in your Angular component:
export class AppComponent implements OnInit {
externalPage: any;
constructor(private http: HttpClient, private sanitizer: DomSanitizer) {}
ngOnInit() {
this.http
.get('https://google.com/', { responseType: 'text' })
.subscribe((res) => {
this.externalPage = this.sanitizer.bypassSecurityTrustHtml(res);
});
}
}
In your HTML code:
<div [innerHtml]="externalPage"></div>
However, for this to function correctly, the external site must have CORS enabled:
access-control-allow-methods: GET, OPTIONS, POST, PUT
access-control-allow-origin: *
If not, you may encounter the following error message:
Access to fetch at 'https://google.com/' from origin 'https://display-external-html-into-angular-vqyiga.stackblitz.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.