Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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 检索数据库 this.studentObservable=this.studentdetails服务.readStudentDatabase(user.uid)作为可观察对象; this.studentObservable.subscribe(临时=>{ this.student=temp作为StudentDetails; });_Angular_Firebase_Google Cloud Firestore - Fatal编程技术网

Angular 检索数据库 this.studentObservable=this.studentdetails服务.readStudentDatabase(user.uid)作为可观察对象; this.studentObservable.subscribe(临时=>{ this.student=temp作为StudentDetails; });

Angular 检索数据库 this.studentObservable=this.studentdetails服务.readStudentDatabase(user.uid)作为可观察对象; this.studentObservable.subscribe(临时=>{ this.student=temp作为StudentDetails; });,angular,firebase,google-cloud-firestore,Angular,Firebase,Google Cloud Firestore,我已从firestore检索到数据收集。 这个this.student有一个名为eventId的属性。我需要从firestore检索该eventId的文档。如何做到这一点而不在订阅中订阅???有两种方法可以防止回调地狱(嵌套订阅) 1。通过方法调用下一个http调用。 this.studentObservable = this.studentDetailsService.readStudentDatabase( user.uid ) as Observable<StudentDetails

我已从firestore检索到数据收集。
这个
this.student
有一个名为
eventId
的属性。我需要从firestore检索该
eventId
的文档。如何做到这一点而不在订阅中订阅???

有两种方法可以防止回调地狱(嵌套订阅)

1。通过方法调用下一个http调用。

this.studentObservable = this.studentDetailsService.readStudentDatabase( user.uid ) as Observable<StudentDetails> ;

this.studentObservable.subscribe( temp => {
         this.student = temp as StudentDetails ;
    });
2。使用承诺

this.studentObservable.subscribe(temp => {
  this.student = temp as StudentDetails;
  this.subscribeSomething();
});
subscribeSomething(): void { this.somethingObservable(this.student).subscribe(() => {}); }
async方法():Promise{
试一试{
this.student=等待这个.studentObservable.toPromise();
}捕获(e){
投掷误差(e);
}
试一试{
const res=等待这个。另一个httptopromise(这个。学生);
}捕获(e){
投掷误差(e);
}
}

有两种方法可以防止回调地狱(嵌套订阅)

1。通过方法调用下一个http调用。

this.studentObservable = this.studentDetailsService.readStudentDatabase( user.uid ) as Observable<StudentDetails> ;

this.studentObservable.subscribe( temp => {
         this.student = temp as StudentDetails ;
    });
2。使用承诺

this.studentObservable.subscribe(temp => {
  this.student = temp as StudentDetails;
  this.subscribeSomething();
});
subscribeSomething(): void { this.somethingObservable(this.student).subscribe(() => {}); }
async方法():Promise{
试一试{
this.student=等待这个.studentObservable.toPromise();
}捕获(e){
投掷误差(e);
}
试一试{
const res=等待这个。另一个httptopromise(这个。学生);
}捕获(e){
投掷误差(e);
}
}
您可以在地图中获取数据,然后才能将您的逻辑设置为您想要做的事情

async method(): Promise<void> {
  try {
    this.student = await this.studentObservable.toPromise();
  } catch(e) {
    throw Error(e);
  }
  try {
    const res = await this.anotherHttpToPromise(this.student);
  } catch(e) {
    throw Error(e);
  }
}
this.studentObservable=this.studentdetails服务.readStudentDatabase(user.uid)作为可观察对象;
这是值得观察的
.管道(地图(数据))
.订阅(数据=>{
this.student=temp作为StudentDetails;
});
您可以在地图中获取数据,然后才能将您的逻辑设置为您想要做的事情

async method(): Promise<void> {
  try {
    this.student = await this.studentObservable.toPromise();
  } catch(e) {
    throw Error(e);
  }
  try {
    const res = await this.anotherHttpToPromise(this.student);
  } catch(e) {
    throw Error(e);
  }
}
this.studentObservable=this.studentdetails服务.readStudentDatabase(user.uid)作为可观察对象;
这是值得观察的
.管道(地图(数据))
.订阅(数据=>{
this.student=temp作为StudentDetails;
});

您可以在这里输入更多的代码和您想输入的内容吗?您可以输入更多的代码和您想输入的内容吗?数据是什么?这样做的好处是什么?这样,您可以在订阅方法之前获取数据,并将其转换为任何logicin映射(数据),什么是数据?这样做的好处是什么?这样你可以在订阅方法之前获取数据并转换为任何逻辑。你能给我一个wat将studentObservable解包到一个普通对象吗?我不明白。你能给我一个wat将studentObservable解包到一个普通对象吗,我可以用在任何地方?我不明白