如何解决角度10:使用变量
我正在尝试使用下面的组件设置IFrame源输入。
由于某种原因,它不起作用,没有显示任何网页。如何正确设置输入源?
呼叫方式:
<app-viewer-iframe-two
[url1]="'http://www.food.com'"
[url2]="'http://www.car.com'"
>
</app-viewer-iframe-two>
打字稿:
export class ViewerIframeTwoComponent implements OnInit {
constructor() { }
@Input() url1: string;
@Input() url2: string;
ngOnInit(): void {
}
}
HTML:
<div class="box">
<iframe class="iframe-one" src="{{url1}}" frameborder="0"
scrolling="yes" align="left"> </iframe>
</div>
<div class="box">
<iframe class="iframe-two" src="{{url1}}" frameborder="0"
scrolling="yes" align="right"></iframe>
</div>
错误:
从未设置任何源,
资源:这仅适用于Angular 1
How to set an iframe src attribute from a variable in AngularJS
解决方法
是的,将与Angular.js中相同的内容放入url仍然是不安全的。只需绕过它-它仍然是不安全的,但是您将承担责任而不是有角的开发人员。
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
写为 constructor(public sanitizer: DomSanitizer) { }
ngOnInit() {
this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。