Reputation: 21
i have app for angular 13 i use mat table and i want to display icon for downloading file but i want to hide this icon when the link is not existing yet. html code
</ng-container>
<ng-container matColumnDef="fileUrl">
<th mat-header-cell *matHeaderCellDef> url </th>
<td mat-cell *matCellDef="let element"> <a [href]="setFile(element.fileUrl)" target="_blank"><i class="fas fa-file-pdf"></i></a></td>
</ng-container>
Ts code:
setFile(url:string) {
if(url !=null){
this.DisplayFileUrl=this.congesService.getFilePath(url)
return this.DisplayFileUrl
}
someone can help me pls thinks
Upvotes: 0
Views: 557
Reputation: 3127
Try this:
setFile(url:string) {
if(url !=null){
this.DisplayFileUrl=this.congesService.getFilePath(url)
return this.DisplayFileUrl
} else return null;
}
And in your html:
<ng-container matColumnDef="fileUrl">
<th mat-header-cell *matHeaderCellDef> url </th>
<td mat-cell *matCellDef="let element"> <a *ngIf="setFile(element.fileUrl)" [href]="setFile(element.fileUrl)" target="_blank"><i class="fas fa-file-pdf"></i></a></td>
</ng-container>
ngIf does the magic!
Greetings, Flo
Upvotes: 1