Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
Firebase AngularFire2可观测火基永不结束(列表为空)_Firebase_Ionic Framework_Observable_Angularfire2 - Fatal编程技术网

Firebase AngularFire2可观测火基永不结束(列表为空)

Firebase AngularFire2可观测火基永不结束(列表为空),firebase,ionic-framework,observable,angularfire2,Firebase,Ionic Framework,Observable,Angularfire2,我试图查询一个空的firebase列表。问题是,可观察方法subscribe永远不会完成,我无法向用户显示ddbb列表为空 函数GetUserAppointsByDate(…)正在调用GetUserAppoints(…),其中.database.list('/appointment/users/'+user\u uid)是输入用户(user\u uid)的空的firebase列表 我应该如何管理对firebase的空查询 提前谢谢 getUserAppointmentsByDate(user_u

我试图查询一个空的firebase列表。问题是,可观察方法subscribe永远不会完成,我无法向用户显示ddbb列表为空

函数GetUserAppointsByDate(…)正在调用GetUserAppoints(…),其中.database.list('/appointment/users/'+user\u uid)是输入用户(user\u uid)的空的firebase列表

我应该如何管理对firebase的空查询

提前谢谢

getUserAppointmentsByDate(user_uid: string, start: string, end: string) {

  if (typeof (user_uid) == "undefined" || typeof (start) == "undefined" || typeof (end) == "undefined") {
    console.error("invalid argument for getPatientReport");
    return;
  }

  return this.getUserAppointments(user_uid)
  .map(
    (appointment) => {
      return appointment
        .filter((appointment) => {
          var appointmentStart = new Date(appointment.start);
          var startFilter = new Date(start);
          var endFilter = new Date(end);
          //Filter old, not cancelled and not deleted
          return (appointmentStart.getTime() < endFilter.getTime())
            && (appointmentStart.getTime() > startFilter.getTime())
            && (appointment.status != AppointmentStatus.CANCELLED);
        });
    })
}

getUserAppointments(user_uid: string): any {
   return this.database.list('/appointment/users/' + user_uid) //*THIS IS AN EMPTY LIST
    .mergeMap((appointments) => {
      return Observable.forkJoin(appointments.map(
        (appointment) => this.database.object('/appointment/list/' + appointment.$key)
      .take(1)))
  })
}
getUserAppointsByDate(用户uid:string,开始:string,结束:string){
if(typeof(user_uid)=“未定义”| | typeof(start)=“未定义”| | typeof(end)=“未定义”){
错误(“getPatientReport的参数无效”);
返回;
}
返回此。GetUserAppoints(用户\u uid)
.地图(
(委任)=>{
回程预约
.filter((约会)=>{
var appointmentStart=新日期(appointment.start);
var startFilter=新日期(开始);
var endFilter=新日期(结束);
//筛选旧的、未取消的和未删除的
返回(appointmentStart.getTime()startFilter.getTime())
&&(appointment.status!=AppointmentStatus.CANCELLED);
});
})
}
getUserAppointments(user\u uid:string):任意{
返回此.database.list('/appointment/users/'+user\u uid)/*这是一个空列表
.mergeMap((约会)=>{
返回可观察的.forkJoin(appoints.map(
(约会)=>this.database.object('/appointment/list/'+appointment.key)
(一)
})
}

作为
this.database.list('/appointment/users/'+user\u uid)
返回一个空数组
Observable.forkJoin(appointment.map(
complete而不发出任何值(这是forkJoin的预期工作方式)。在这种情况下,您有两个选项,在complete函数中处理

.subscribe(
  res => console.log('I got values'),
  err => console.log('I got errors'),
  // do it whatever you want here
  () => console.log('I complete with any values')
)
if语句中的句柄

import { of } from 'rxjs/observable/of';
...
return this.database.list('/appointment/users/' + user_uid)
    .mergeMap((appointments) => {
      if (appointments.length === 0) return of([]);
      return Observable.forkJoin(appointments.map(
        (appointment) => this.database.object('/appointment/list/' + appointment.$key)
      .take(1)))
  })

非常感谢,你真的救了我一天!!我用了([])的方法