Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用subscribe处理后可观察到的角度返回_Angular_Angular5_Angular Observable - Fatal编程技术网

Angular 使用subscribe处理后可观察到的角度返回

Angular 使用subscribe处理后可观察到的角度返回,angular,angular5,angular-observable,Angular,Angular5,Angular Observable,在Angular 5中,我需要进行一个HTTPGET调用,处理输出,然后将处理后的输出作为一个可观察对象本身返回。我真不知道该怎么做。我目前正在获取/处理数据,如下所示: this.http.geturl{ headers:this.headers }.subscribex=>{ 让条形码=x.result.mapr=>{ 返回r.u_空间_条码; }; }; 因此,现在我想将条形码作为可观察的发送回去,您应该能够使用: this.http.get<BarcodeResponse>(

在Angular 5中,我需要进行一个HTTPGET调用,处理输出,然后将处理后的输出作为一个可观察对象本身返回。我真不知道该怎么做。我目前正在获取/处理数据,如下所示:

this.http.geturl{ headers:this.headers }.subscribex=>{ 让条形码=x.result.mapr=>{ 返回r.u_空间_条码; }; };
因此,现在我想将条形码作为可观察的

发送回去,您应该能够使用:

this.http.get<BarcodeResponse>(url, {
headers: this.headers })
  .map(value => {
   //Do the parsing you need
  return value
});
很容易将Rxjs映射操作符与原型修补方法混合使用

您可以通过以下两种方式导入它: 导入'rxjs/add/operator/map'


从“rxjs/operators”导入{map}

然而,我不太清楚你“想把条形码作为可观察的东西发送回去”是什么意思。你想把它们像那样发送回api吗?将其从服务返回到组件?谢谢。我只需要添加import'rxjs/add/operator/map';到我的档案。谢谢。我更喜欢你展示的第二种形式,因为它与其他进口产品更为一致。@Gargoyle没错。它可以在一行中导入多个运算符从“rxjs/operators”导入{map,mergeMap,forkJoin},使代码更清晰: