<iframe
[src]="iframeUrl"
class="Iframe"
width="300px"
height="500px"
style="padding: 0"
scrolling="no"
frameborder="0"
>
<p>当前浏览器不支持iframe</p>
</iframe>
通过[src]绑定路径,再在ts文件里将路径地址转化为安全路径:
export class IndexComponent implements OnInit {
url = 'http://localhost:4200/assets/index.html';
iframeUrl: SafeResourceUrl;
constructor(private sanitizer: DomSanitizer) {
this.iframeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
}
ngOnInit() { }
}
即可。