【发布时间】:2020-11-08 20:31:45
【问题描述】:
我是 Angular 新手,在我了解发生了什么之前要爬一座小山,使用 Firestore 中的 observables 让我很困惑。我需要一个服务调用中的 ID 字段来从以下两个服务调用中获取数据,同时避免可怕的未定义。我们如何做到这一点?
this.myMatch = this.route.snapshot.paramMap.get("createdMatchIdKey");
this.golfDataService.GetSelectedMatch(this.myMatch)
.subscribe(result => {
this.match = result;
this.setupTable(this.match.matchCourseId);
this.golfDataService.GetSelectedGolfCourse(this.match.matchCourseId)
.subscribe(result => {
this.course = result;
console.log(this.course);
})
this.golfDataService.GetSelectedCourseTees(this.match.matchCourseId)
.pipe(takeUntil(this.onDestroy))
.subscribe(result => {
this.tees = result;
console.log(this.tees);
for (var i = 0; i < this.tees.length; i++) {
this.golfDataService.GetHoles(this.tees[i].teeIdKey)
.subscribe(result => {
console.log(this.teeHoleInfo);
this.teeHoleInfo.push(result);
console.log(this.match);
})
}
})
})
【问题讨论】:
标签: angular google-cloud-firestore rxjs