【发布时间】:2022-01-27 07:35:01
【问题描述】:
我有以下问题:我想使用默认图像,直到通过异步调用加载另一个图像。问题是,遵循此How do I get a placeholder image to load when my image is still loading from server 并使用此代码我得到两个图像,而不是一个替换另一个。我应该修改什么?
async getData() {
await this.gs.getMaxGifs(this.name, this.offset).subscribe((response: any) => {
this.result.push(...response.data);
if (this.value == 'asc') {
this.result.sort((val1, val2) => {
return new Date(val1.import_datetime).getTime() - new Date(val2.import_datetime).getTime() //ASC
})
}
else {
this.result.sort((val1, val2) => {
return new Date(val2.import_datetime).getTime() - new Date(val1.import_datetime).getTime() //DESC
})
}
this.offset += 50;
if (this.result.length != response.pagination.total_count) {
this.getData()
}
});
}
.html 页面:
<ion-grid fixed>
<ion-row>
<ion-col size="4" *ngFor="let r of result; let i = index">
<ion-card>
<ion-card-content>
<img #userImage src={{r.images.downsized.url}} width="300" height="200" (click)="getDetails(i)">
<img *ngIf="!userImage.complete" src="../../../assets/error.png">
</ion-card-content>
<ion-card-header *ngIf="clicked === i">
<ion-card-title>
title: {{r?.title}}
</ion-card-title>
<ion-card-subtitle>username: {{r?.username}}</ion-card-subtitle>
<ion-card-subtitle>import date:{{r?.import_datetime}}</ion-card-subtitle>
</ion-card-header>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
【问题讨论】:
-
在加载之前隐藏图像可能会更好,但如果您绝对需要占位符图像,您可以将其作为 Base64 表示形式嵌入到代码库中。
标签: angular ionic-framework placeholder