HTML:
<mat-list-item role="listitem" *ngFor="let item of uploadedFiles">
<div class="list-files">
<span><a class="showlink"(click)="downloadFile(item.certificate_name,item.uploaded_doc_name)">{{item.uploaded_doc_name}}</a></span>
<!-- <span>{{item.certificate_name | spliter}}</span> -->
<span>{{item.expiry_date}}</span>
<div class="btn-custom" (click)="delete(item)">Remove</div>
</div>
</mat-list-item>
component.ts: (Вот мой код для загрузки файла ... Он загружает только текстовый файл ... но мне нужно скачать, какой у меня есть файл загрузил, что я должен скачать здесь .. Затем перед загрузкой файл должен просмотреть в новой вкладке .. не могли бы вы помочь мне сделать это?)
downloadFile(file_id, filename){
const payload ={
"company_id":this.data.company_id,
"module_name": "Agent",
"file_id":file_id
}
this.downloadFileError.unsubscribe()
this.downloadFileSuccess.unsubscribe()
this.store.dispatch(new DownloadFile(payload))
this.downloadFileSuccess = this.store.pipe(select(getDownloadFileSuccess)).subscribe(result => {
if(!!result){
let dataType = result.type;
let binaryData = [];
binaryData.push(result.data);
let downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, {type: dataType}));
if(filename){
downloadLink.setAttribute('download', filename);
}
document.body.appendChild(downloadLink);
downloadLink.click();
downloadLink.parentNode.removeChild(downloadLink);
this.store.dispatch(new GetDownloadFileSuccess(null))
}
})
this.downloadFileError = this.store.pipe(select(getDownloadFileError)).subscribe(result => {
if(!!result){
console.log(result)
}
})
}