Indra suandi
Indra suandi

Reputation: 161

Refresh image URL in ionic 2

I have this HTML syntaks for loop my URL, the URL for get an image from my directory by internet, but when image changed in my server, the application still showed last image before I update, I was only change image not name.

<ion-card style="margin: auto">
    <ion-card-header class ="head" style="background-color: gray !important">
      <font color="White">{{dt.desc}}</font>
    </ion-card-header>
    <img src= {{dt.name}} >  
</ion-card>

Whats wrong with this, and how to make image change whenever i change image in server? In my case the image can replace to new image I've update when I uninstall that apps

Upvotes: 0

Views: 2760

Answers (3)

Ahmed El-Kady
Ahmed El-Kady

Reputation: 11

use *ngIf if it only one image use *ngFor if it array

Upvotes: 0

Diluk Angelo
Diluk Angelo

Reputation: 1503

You can use this trick to add a random number after the url so the ionic app will refresh the link thinking its a new link.

this.dt.name = 'www.yourimage.com/image.jpeg?random+\=' + Math.random());

Upvotes: 4

Omsl
Omsl

Reputation: 302

Can you use https://ionicframework.com/docs/api/components/refresher/Refresher/. But you have to retake your data in doRefresh(refresher).

Upvotes: 0

Related Questions