我的输入中出现以下错误:
SafeValue must use [property]=binding: http://www.myurl.com (see http://g.co/ng/security#xss)
我在我的组件中做了:
this.myInputURL = this.sanitizer.bypassSecurityTrustUrl('http://www.myurl.com');
在我的模板中:
Share URL: <md-input [value]="myInputURL" type="text"></md-input>
怎么了?
最佳答案
改变这个
this.sanitizer.bypassSecurityTrustUrl('http://www.myurl.com');
到
this.sanitizer.bypassSecurityTrustResourceUrl('http://www.myurl.com');
两种选择的区别
绕过SecurityTrustUrl
Bypass security and trust the given value to be a safe style URL, i.e. a value that can be used in hyperlinks or
<img src>
. source angular.io
绕过SecurityTrustResourceUrl
Bypass security and trust the given value to be a safe resource URL, i.e. a location that may be used to load executable code from, like
<script src>
, or<iframe src>
. source angular.io
关于angular - SafeValue 必须使用 [property]=binding :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39517394/