I have been trying in Angular2/4 to make something like when page renders it checks for a file and if file exists it shows a checkbox icon while if it doesnot exist then a download icon is shown. But it runs into infinite loop, it is suggested to use a boolean variable but my elements are dynamic and there can be any number of download links so predefined variables are not an option.
Angular2 Code
<div *ngFor="let item of getItems();">
<div ngIf="fileExists(item.url); then example2 else example1"></div>
<ng-template #example1>
<ion-icon class="myicon" name="download" color="primary"></ion-icon>
</ng-template>
<ng-template #example2>
<ion-icon class="myicon" name="checkbox" color="secondary"></ion-icon>
</ng-template>
</div>
TypeScript function to check if file exists
fileExists(url)
{
let path = "notif/"+url.substr(url.lastIndexOf('/')+1);
this.file.checkFile(this.file.externalRootDirectory, path).then(_ => {
console.log('File exists');
return true;
}).catch(err => {
console.log(err);
return false;
});
}