簡體   English   中英

訂閱處理后角返回可觀察

[英]Angular return Observable after processing with subscribe

在Angular 5中,我需要進行HTTP GET調用,處理輸出,然后將該處理后的輸出作為Observable本身返回。 我真的很困惑如何做到這一點。 我目前正在像這樣獲取/處理數據:

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

所以現在我想將barcodes作為Observable<string[]>發送回去

您應該可以使用:

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

將Rxjs map運算符與原型修補方法混合在一起很容易。

您可以通過import 'rxjs/add/operator/map';來導入它import 'rxjs/add/operator/map';

import { map } from 'rxjs/operators';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM