angular中是用iframe标签

angular中使用iframe标签,那么iframe的src直接写变量,变量值为:“http://www.baidu.com”,跳转的是,是有问题的;
正确使用为:

// html:
<iframe *ngIf="!!jumpLink" [src]="jumpLink" frameborder="0"></iframe>
// js:
import {DomSanitizer} from "@angular/platform-browser";
private sanitizer:DomSanitizer
// 具体使用:
let jumpLink=res.key+'&tenant_id='+this.tenantId; // 返回的地址+参数
this.jumpLink=this.sanitizer.bypassSecurityTrustResourceUrl(jumpLink); // 信任该url

参考地址:
https://segmentfault.com/a/1190000008809095

猜你喜欢

转载自blog.csdn.net/weixin_42995876/article/details/86174455