Gargoyle
Gargoyle

Reputation: 10294

Angular return Observable after processing with subscribe

In Angular 5 I need to make an HTTP GET call, process the output, and then return that processed output as an Observable itself. I'm really confused on how to do that. I'm currently getting/processing the data like so:

this.http.get<BarcodeResponse>(url, {
  headers: this.headers
}).subscribe(x => {
  let barcodes = x.result.map(r => {
    return r.u_space_barcode;
  });
});

So now I want to send barcodes back as the Observable<string[]>

Upvotes: 0

Views: 594

Answers (2)

Haifeng Zhang
Haifeng Zhang

Reputation: 31885

It is easy to mix Rxjs map operator with the prototype patching method.

You can import it either by import 'rxjs/add/operator/map';

or import { map } from 'rxjs/operators';

Upvotes: 0

Lars
Lars

Reputation: 788

You should be able to use:

this.http.get<BarcodeResponse>(url, {
headers: this.headers })
  .map(value => {
   //Do the parsing you need
  return value
});

Upvotes: 1

Related Questions