AngularFire2在订阅时检查列表是否为空

AngularFire2在订阅时检查列表是否为空,angular,firebase,ionic2,angularfire2,Angular,Firebase,Ionic2,Angularfire2,我使用AngularFire2和Ionic2应用程序。我试图从数据库中加载元素列表,并在加载时显示微调器 当列表为空时,我会遇到一个问题,我不知道如何通知控制器停止微调器,因为在新添加之前不会有任何数据。我可能没有正确的结构 这是我服务的摘录: this.userTourList = this.af.database.list('/userProfiles/' + this.userId + '/tours/'); this.userTourList.subscribe((response) =

我使用AngularFire2和Ionic2应用程序。我试图从数据库中加载元素列表,并在加载时显示微调器

当列表为空时,我会遇到一个问题,我不知道如何通知控制器停止微调器,因为在新添加之前不会有任何数据。我可能没有正确的结构

这是我服务的摘录:

this.userTourList = this.af.database.list('/userProfiles/' + this.userId + '/tours/');
this.userTourList.subscribe((response) => {
    response.map((tourData) => {
        //Create and fill a TourSnapshot component
        let tourSnap = new TourSnapshot(tourData.name, tourData.$key);
        tourSnap.description = tourData.description;
        //[..]
        this.tours.push(tourSnap);
        //Return an array through my own observable
        return this.toursObservable.next(this.tours);
    });
}
这是我的控制器:

let loader = this.loadingCtrl.create({
    content: "Loading tours..."
});
loader.present().then(() => {
   //The list will be updated automatically
   tourData.getExpertTourList().subscribe(tourList => {
      this.tourList = tourList;
      loader.dismiss().catch(() => {});
   });
});
如果列表为空,我的加载程序将永远不会被解除(直到完成新的添加)。我考虑对我的服务中的可观察对象使用isEmpty()方法,如下所示:

this.userTourList.isEmpty().subscribe(isEmpty => {
//Force a return if the "tours" node is empty to indicate to the controller
//that nothing else will be returned before a new add
    if (isEmpty) {
       return this.userToursObservable.next(this.tours);
    }
});
但我总是得到一个错误的isEmpty值。我如何在不额外调用数据库的情况下检查列表是否为空?(如果可能的话)


谢谢

基于@cartant comment,我在调用map()方法之前添加了一个列表大小检查


您需要包含更多的代码来显示您在服务中所做的事情。AngularFire2
列表
如果没有数据,可观测对象将发出一个空数组,因此这取决于您的服务中发生了什么。谢谢您的回答。我更新了问题。事实上,AngularFire2列表返回一个空数组,在调用map()方法并直接返回空数组之前,我必须检查它。我将把它作为解决方案发布。再次感谢你。
this.userTourList = this.af.database.list('/userProfiles/' + this.userId + '/tours/');
this.userTourList.subscribe((response) => {
    if (response.length == 0) {
       //Return an empty array anyway
       return this.toursObservable.next(this.tours);
    }
    response.map((tourData) => {
        //Create and fill a TourSnapshot component
        let tourSnap = new TourSnapshot(tourData.name, tourData.$key);
        tourSnap.description = tourData.description;
        //[..]
        this.tours.push(tourSnap);
        //Return an array through my own observable
        return this.toursObservable.next(this.tours);
    });
}