ios - ionic 4 : The "src" content of an "img" tag is not updating when I change it from the controller in IOS

标签 ios ionic-framework ionic4

我正在开发适用于 Android 和 IOS 的应用程序。

我有一个个人资料页面,用户可以在其中更改个人资料图片。照片出现在 View 中并实时更改。

我的代码在 View 中是这样的:

<img alt="logo" style="width:15vh; height:15vh; border-radius: 50%;" src="{{pictureusuariomenu}}">

图片usuarimenu 是在 Controller 中找到的变量。

使用该变量,我所做的是我上传的图像的 URL,我在那里更新它。这是功能:
updateStoredImages(name) {
    this.storage.get(STORAGE_KEY).then(images => {
        let arr = JSON.parse(images);
        if (!arr) {
            let newImages = [name];
            this.storage.set(STORAGE_KEY, JSON.stringify(newImages));
        } else {
            arr.push(name);
            this.storage.set(STORAGE_KEY, JSON.stringify(arr));
        }

        let filePath = this.file.dataDirectory + name;
        let resPath = this.pathForImage(filePath);
       // alert(resPath);
        this.urlImage=resPath;


        let newEntry = {
            name: name,
            path: resPath,
            filePath: filePath
        };
        this.images=[]; //borrar las imagenes anteriores (no crear la lista de imagenes)
        this.images = [newEntry, ...this.images];
        this.urlImage = this.images[0].path;
        this.colocarImagenEnProfile(this.urlImage);     
        this.ref.detectChanges(); // trigger change detection cycle
    });
}

在这一行:
this.colocarImagenEnProfile(this.urlImage);

我要做的是:
colocarImagenEnProfile(newFileName){
    this.pictureusuariomenu=newFileName;
}

现在在 android 中,这种更新配置文件图像的方式工作正常:

前:

enter image description here

后:

enter image description here

但在 IOS 中,这是行不通的。 View 根本没有更新

前:

enter image description here

后:

enter image description here

什么都没有出现,只有几个字母。但是 View 在IOS中没有更新。

会是什么呢?

我的规范:

enter image description here

最佳答案

你忘了绑定(bind)它。把它代替你的 HTML 标签:

<img alt="logo" style="width:15vh; height:15vh; border-radius: 50%;" [src]="pictureusuariomenu">

我不知道为什么,但你必须以这种方式绑定(bind)它。
此外,您必须使用 window.Ionic.WebView.convertFileSrc();功能,如果使用角度,则需要对其进行 sanitizer 。像这样:
this.sanitize.bypassSecurityTrustResourceUrl(window.Ionic.WebView.convertFileSrc(path))

关于ios - ionic 4 : The "src" content of an "img" tag is not updating when I change it from the controller in IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62159457/

相关文章:

ios - 从 objective-c 中的 sqlite 数据库中检索表名

iphone - NSDate alloc init & 获取发送到释放实例的消息

javascript - 添加重定向后,AngularJS 无法将 JSON 数据发送到数据库

angular - 将 NGXS 状态分解为更小的可维护部分,但又保持它们彼此可访问的最佳方法是什么?

android - mainActivity 找不到 Ionic 4 电容视频播放器插件

nested - 在 ionic4 中使用嵌套子路由时,路由在一次主导航更改后停止工作

ios - 带有 UIButton 的 SWReveal

iphone - 使 SKScene 的背景透明不起作用...这是一个错误吗?

javascript - 如何在 angularjs 中动态追加 <li> ?

angularjs - Ionic/Angular JS - $scope 问题 : Cannot read property 'length' of undefined