I am supplying a downloadable data to child through @input
value. when user click on download link it's downloading the file without any issue.
But whenever there is a change going on and observed by ngOnchanges
- triggers the download again and i am getting downloaded a unknown file. so, how to fix it or how can i make only it download the file on user click alone?
on user click i am triggering download event.
@Input() cpDownloadedFile: any;
initDownloadFile(fileData) {
this.fileDownloaded.emit(fileData.Id);
}
ngOnChanges() {
change1,
change 2
//other changes goes here
if (this.cpDownloadedFile && changes.cpDownloadedFile) {
const element = document.createElement('a');
element.href = URL.createObjectURL(this.cpDownloadedFile);
element.download = this.fileName.replace(/ /g, '').replace(/\_(?=[^_]*$).*(?=\.)/g, '');
document.body.appendChild(element);
element.click();
}
}