typescript - How to download a pdf using fileSaver and Angular 2 -


i stored pdf file inside angular 2 project. want download file onclick of button. here html code-

<a class="btn-u btn-u-sm" (click)="savedemo()">download <i class="fa fa-angle-double-right margin-left-5"></i></a> 

and component.ts

import { component } '@angular/core'; import { registrationcomponent } '../registration/app.registration'; import { saveas } 'file-saver';  @component({     templateurl: './app.pronto.html' }) export class prontocomponent {    savedemo() {       let file = new blob(['../../../files/skybase.pdf'], { type: 'application/pdf;charset=utf-8' });       saveas(file, 'skybase.pdf')    } } 

but blank pdf downloading. should do?

if file on same directory of project

why using coding , can directly use download attribute of a tag

<a href="path_to_pdf" download> 

note : if path correct , file downloaded otherwise blank , same issue in code. check file path , make sure correct.


<a href="path_to_pdf" download="new_filename">

specifies new filename downloaded file

<a href="https://www.w3schools.com/images/myw3schoolsimage.jpg" download="w3logo">w3 logo</a>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -