Ionic 4:当我从 IOS 中的控制器更改它时,"img" 标签的 "src" 内容没有更新
Ionic 4: The "src" content of an "img" tag is not updating when I change it from the controller in IOS
我正在为 Android 和 IOS 开发应用程序。
我有一个个人资料页面,用户可以在其中更改个人资料图片。照片出现在视图中并实时更改。
我的代码在视图中是这样的:
<img alt="logo" style="width:15vh; height:15vh; border-radius: 50%;" src="{{pictureusuariomenu}}">
pictureusuariomenu 是在控制器中找到的变量。
有了这个变量,我所做的是,它是我上传的图像的 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 中,这种在视图中更新个人资料图片的方式工作正常:
之前:
之后:
但在 IOS 这行不通。视图根本没有更新
之前:
之后:
没有出现,只有几个字母。但是视图不会在 IOS.
中更新
会是什么?
我的规格:
你忘记绑定了。用它代替你的 HTML 标签:
<img alt="logo" style="width:15vh; height:15vh; border-radius: 50%;" [src]="pictureusuariomenu">
我不知道为什么,但你必须那样绑定它。
另外,你必须使用 window.Ionic.WebView.convertFileSrc();功能,如果使用 angular 你需要清理它。像这样:
this.sanitize.bypassSecurityTrustResourceUrl(window.Ionic.WebView.convertFileSrc(path))
我正在为 Android 和 IOS 开发应用程序。
我有一个个人资料页面,用户可以在其中更改个人资料图片。照片出现在视图中并实时更改。
我的代码在视图中是这样的:
<img alt="logo" style="width:15vh; height:15vh; border-radius: 50%;" src="{{pictureusuariomenu}}">
pictureusuariomenu 是在控制器中找到的变量。
有了这个变量,我所做的是,它是我上传的图像的 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 中,这种在视图中更新个人资料图片的方式工作正常:
之前:
之后:
但在 IOS 这行不通。视图根本没有更新
之前:
之后:
没有出现,只有几个字母。但是视图不会在 IOS.
中更新会是什么?
我的规格:
你忘记绑定了。用它代替你的 HTML 标签:
<img alt="logo" style="width:15vh; height:15vh; border-radius: 50%;" [src]="pictureusuariomenu">
我不知道为什么,但你必须那样绑定它。 另外,你必须使用 window.Ionic.WebView.convertFileSrc();功能,如果使用 angular 你需要清理它。像这样:
this.sanitize.bypassSecurityTrustResourceUrl(window.Ionic.WebView.convertFileSrc(path))