html - 为什么不显示里面使用 *ngFor 循环?
问题描述
我有一些代码旨在显示用户个人资料图片,无论是默认图片还是用户上传的图片。现在, img [src]="profileImage" 本身就完美地显示了图像。但是,当我将其放入 ion-col 时,它不会显示。
下面是我正在使用的以下代码
HTML
<ion-col *ngFor="let item of students" >
<div class= "imageHold" >
<img [src]= "profileImage">
</div>
</ion-col>
TS
export class EditProfilePage implements OnInit {
profileImage : any;
ngOnInit() {
this.profileImage = ["./assets/imgs/user.png"]
this.students = data.map(e => {
return {
id: e.payload.doc.id,
isEdit: false,
userName: e.payload.doc.data()['userName'],
userBio: e.payload.doc.data()['userBio'],
profileImage: e.payload.doc.data()['profileImage'],
};
})
console.log(this.students);
}
上传个人资料图片的firebase代码片段
this.firebaseService.uploadImage(image_src, randomId)
.then(photoURL => {
this.profileImage = photoURL;
loading.dismiss();
toast.present();
解决方案
你有 profileImage 作为字符串数组,并且 [src] 只接受字符串
试试这样
this.profileImage = "./assets/imgs/user.png"; //don't declare this as string
或者如果您有多个图像,则尝试使用索引
this.profileImage = ["./assets/imgs/user.png","./assets/imgs/user1.png"]
在 HTML 中
<img [src]= "profileImage[0]">
推荐阅读
- python - 如何使用 Python 安全地编码内容配置 HTTP 标头?
- greenplum - 如何在Greenplum中实现负载均衡
- php - 使用 curl 登录返回相同的登录页面
- java - 如何使用spring get bean将父引用分配给子对象
- python - 添加检查问题
- c# - 为什么添加任务时会创建列表的新实例?
- amazon-web-services - 在 lambda 函数中调用外部邮件 api
- vue.js - 按结果迭代分组
- ios - 在 iOS SDK 的另一个模块中添加一个 Objective-C 框架
- null - 使用 Mockito doReturn 总是返回 null