ai didi

angular - ionic `` 不适用于 domSanitizer, "SafeValue must use [property]=binding"失败

转载 作者:行者123 更新时间:2023-12-05 07:20:30 24 4
gpt4 key购买 nike

参见示例:https://stackblitz.com/edit/ionic-v4-angular-tabs-6um4j8

我有以下 url(来自本地文件系统)

url = 'capacitor://localhost/_capacitor_file_/Users/user/Library/.../Library/Caches/img/C409D956-DE09-406D-A7EF-3207DF705B64-L0-001~100x100.JPG';
safeUrl = domSanitizer.bypassSecurityTrustUrl(url);

我在模板文件中有这个:

<ion-virtual-scroll>
<img [src]="safeUrl">
<ion-img [src]="safeUrl"></ion-img>
</ion-virtual-scroll>

safeUrl使用 HTML IMG 标签正确显示,但在 <ion-img> 中显示相同的 url给出以下错误:

"capacitor://localhost/SafeValue must use [property]=binding: capacitor://localhost/_capacitor_file_/Users/user/Library/.../Library/Caches/img/C409D956-DE09-406D-A7EF-3207DF705B64-L0-001~100x100.JPG (see http://g.co/ng/security#xss)

最佳答案

看起来你不需要清理 url,而是尝试注入(inject) webview 并使用它来转换 FileSrc

import { WebView } from '@ionic-native/ionic-webview/ngx';


...

constructor(private webview: WebView) {}

...

const localSrc = this.webView.convertFileSrc(url);
this.safeUrl = localSrc;

关于angular - ionic `<ion-img>` 不适用于 domSanitizer, "SafeValue must use [property]=binding"失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57476373/

24 4 0
文章推荐: swift - 我在 cygwin 上得到 ":0: error: could not load the swift standard library"
文章推荐: postman - 使用来自 Postman 的 httpOnly cookie
文章推荐: python - 在 cmd 中使用 pip 安装 matplotlib 完成而没有实际安装
文章推荐: vbscript - IBM PCOMM - 无法从另一个 vbs 宏中调用 vbs 宏
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com