How to download pdf file in angular 2

In Angular 6, In service downloadPdfFile.service.ts and create the following things. Import Statement import { HttpClient, HttpHeaders } from ‘@angular/common/http’; import { map } from ‘rxjs/operators’; Method for download pdf downloadPDF(dataObj) { let headerOptions = new HttpHeaders({ ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/pdf’ // ‘Accept’: ‘application/octet-stream’, // for excel file }); let requestOptions = { headers: headerOptions, … Read more

How I add Headers to http.get or in Typescript and angular 2?

You can define a Headers object with a dictionary of HTTP key/value pairs, and then pass it in as an argument to http.get() and like this: const headerDict = { ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/json’, ‘Access-Control-Allow-Headers’: ‘Content-Type’, } const requestOptions = { headers: new Headers(headerDict), }; return this.http.get(this.heroesUrl, requestOptions) Or, if it’s a POST request: … Read more