0

I am calling a service which builds and returns an http call return =(this.http.get(API URL). I subscribe to the service as below and it tells me that the value is undefined, I should try passing in an Observable:

documentDownload(documentUrl) {
    const queryParams = new HttpParams()
      .set('Code', this.code);
    return this.http.get((documentUrl), {params: queryParams}).subscribe(resp => this.DocDownload(resp));
  }

below is the docDownload to actually open the pdf:

  DocDownload(data) {
    const blob = new Blob([data], { type: 'application/pdf' }); //octet-stream
    const url = window.URL.createObjectURL(blob);
    window.open(url);
  }

I believe I am subscribing correctly and I've tested the service it returns a valid link so why is that it's running into this undefined error?

Haq.H
  • 863
  • 7
  • 20
  • 47
  • You mean the return value of `documentDownload ` It should return a `Subscription`. – Günter Zöchbauer Mar 14 '18 at 18:21
  • Check [this related question](https://stackoverflow.com/questions/34149741/how-to-receive-blob-responses-using-angulars-2-angular-http-module/47015631#47015631) – sabithpocker Mar 14 '18 at 18:28
  • The related question worked. It wasn't working b/c I didn't have the responsetype defined. Thanks a lot! – Haq.H Mar 14 '18 at 20:32

0 Answers0