angular项目中要以变量的形式,外部引入src,结果报错如下:
<iframe name="myiframe" id="iframe1" [src]="srcUrl" width="100%" height="700px" ></iframe>
解决方式:
1.导入DomSanitizer
import { DomSanitizer} from '@angular/platform-browser';
2.引用DomSanitizer,并转换url
srcUrl:any;
constructor(private sanitizer: DomSanitizer) {
this.srcUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url);
}