可通过使用Angular DOMSanitizer对url进行处理,确保安全地嵌入到iframe中。代码示例如下:
import { DomSanitizer } from '@angular/platform-browser';
constructor(private sanitizer: DomSanitizer) { }
trustUrl(url: string): SafeUrl { return this.sanitizer.bypassSecurityTrustUrl(url); }
iframeUrl = this.trustUrl('https://example.com');