You should to use DomSanitizer for displaying that URL. This will enable you to create an exception for displaying the URL you want in the iFrame.
You can create a new variable and assign it the sanitized value, then display it in the HTML like this:
Warning! Using bypassSecurityTrustResourceUrl might expose your page to XSS attacks. You should minimize and control this as much as possible. Check the documentation to ensure that you are protecting yourself properly when using DomSanitizer: https://angular.io/api/platform-browser/DomSanitizer
HTML
<iframe [src]="sanitizedURL"></iframe>
JS
//Wherever you are setting the URL, use DomSanitizer. For example:
var URL = this.PostContent.link;
// Use sanitizer for URL
this.sanitizedURL = this.domSanitizer.bypassSecurityTrustResourceUrl(URL);
Your JS full code, including new imports
import { Component, ViewChild } from '@angular/core';
import { ApiProvider } from '../../providers/api/api.service';
import { ActivatedRoute } from '@angular/router';
//Import SafeResourceURL & DomSanitizer
import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'iFrameComponent',
templateUrl: './iFrameComponent.component.html',
styleUrls: ['./iFrameComponent.component.scss'],
})
export class iFrameComponent {
//Declare URL variable
sanitizedURL: SafeResourceUrl;
postid: string;
PostContent:any = [];
theInAppBrowser: any;
constructor(
public api:ApiProvider,
private route: ActivatedRoute,
public domSanitizer: DomSanitizer,
) {
this.postid = this.route.snapshot.paramMap.get('id');
}
getPostContent(){
this.api.get('doctor/' + this.postid ).subscribe((data) => {
this.PostContent = data;
//Set URL
var URL = this.PostContent.link;
// Use sanitizer for URL
this.sanitizedURL = this.domSanitizer.bypassSecurityTrustResourceUrl(URL);
});
}