ฉันมีแอป Angular 6 ฉันกำลังอัพเกรด rxjs เป็น 6
ในแอพเวอร์ชั่นก่อนๆผมต้องโทรแบบนี้ครับ...
ฉันเรียกสิ่งที่สังเกตได้ ทำบางสิ่งด้วยผลลัพธ์ของมัน จากนั้นเรียกสิ่งอื่นที่สังเกตได้โดยใช้ค่าจากครั้งล่าสุด ทำบางสิ่งด้วยผลลัพธ์ของมัน
ทำสิ่งนี้โดยใช้ concatmap รหัสมีลักษณะเช่นนี้ ...
this.service1.getData().concatMap(d1 => {
this.d1Local = d1;
return this.service2.getData(d1);
}).subscribe(
this.d2Local = d2,
error => errorFunction);
ฉันกำลังพยายามเขียนสิ่งนี้ใหม่โดยใช้ rxjs6 และคีย์เวิร์ดไปป์และไม่มี concatmap
ขณะนี้ฉันมี...
this._LocationService.getLocation()
.pipe(
map(location => {
console.log(1);
this.location = location;
return this._GeoCoderService.getAddress(location)
.pipe
(map(address => {
this.address = "You are near " + address;
this.showSpinner = false;
}
))
}
)
);
ฉันไม่เคยเห็นการบันทึก '1' ลงในคอนโซลเลย มีความคิดใดที่ฉันควรทำสิ่งนี้?
อัปเดต:
ฉันรู้ว่ามีรหัสด้านล่าง ฉันคิดว่ามันเกือบจะถูกต้องแล้วที่ฉันไม่เห็นข้อความ condole.log ล่าสุดที่พิมพ์ 1....
this._LocationService.getLocation()
.pipe(map((location: ILocation) => {
this.location = location;
return this._GeoCoderService.getAddress(location);
})
, catchError(error => { this.showSpinner = false; return throwError('Something went wrong!') })
).subscribe(
tap((address: string) => { console.log(1) })
);
ฉันพลาดอะไรไป?
this._GeoCoderService.getAddress
ส่งคืน Observable คุณต้องใช้concatMap
(หรือmergeMap
ในกรณีนี้) คุณต้องสมัครสมาชิกเมื่อสิ้นสุดเครือข่ายด้วย - person martin   schedule 11.07.2018.tap()
ภายในsubscribe()
? - person CozyAzure   schedule 12.07.2018tap
ในsubscribe
- แค่subscribe((address: string) => console.log(1));
- person dsych   schedule 12.07.2018