angular - SafeValue 必须使用 [property]=binding :

标签 angular

我的输入中出现以下错误:

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/

相关文章:

angular - 如何在 Angular 6 中使用 HttpClient get 禁用缓存

javascript - 在 Angular 中将 if 和 else 与 mergeLatest 一起使用

css - 无效的属性值 scss 函数

angular - 在无法识别的 ionic 5 错误元素中显示二维码 ngx-qrcode

css网格,布局问题

angular - 使用 WebPack 在 Web Worker 中运行 Angular 2 应用程序

Angular 2 - 子路由加载父组件

javascript - 如何在 Angular 4 中转换附加反斜杠的双引号字符串

Angular2动态组件

css - Angular Material 2 找不到核心主题