In Angular 5, I want to download an image from localhost (server). I already have the image name with the path as: http://localhost/projectName/uploads/3/1535352341_download.png Now I want to download by clicking on a button.
In the HTML view in Angular, I wrote the following code:
<button (click)="downloadImage(car.carItem.carTitle)" type="button" class="btn btn-sm btn-info btn-action" tooltip="Download Image" placement="left" container="body"><i class="fa fa-download" aria-hidden="true"></i></button>
In the .ts file, I do the following but it opens the image in the same tab:
downloadImage(imagePath){
window.location = imagePath;
}
I have already gone through the post Angular 4 direct download images but unable to find any solution. So please don't mark it as duplicate.