在组件里面引入angular内置的DomSanitizer模块 import { DomSanitizer } from ‘@angular/platform-browser‘; 1 ####在构造器里面定义属性 constructor(private sanitizer: DomSanitizer) {} 1 ####将地址转化为安全地址 this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url); 1 ####在HTML中的写法 <iframe id="treeid" [src]="treeUrl" width="100%" ></iframe>