Firestore:传递angularfire2异步数据,因为Ionic 3 navParams无效

cot*_*riv 14 ionic-framework angularfire2 angular google-cloud-firestore

cities: Observable<any>;


this.cities = this.fsProvider.collection('cities').map(cities => {
    return cities.map(city => {
      city.country = this.fsProvider.doc(`countries/${city.country_id}`);
      return city;
    });
});
Run Code Online (Sandbox Code Playgroud)

city包括country信息作为Observable数据.所以,如果我city作为一个传递到另一个页面navParam,只是this.navCtrl.push(AnotherPage, {city: city}),我无法获得国家信息AnotherPage.

我刚刚在这里添加了演示:https://stackblitz.com/edit/ionic-firestore.

欢迎任何想法.

joe*_*elm 0

您的国家/地区集合设置正确吗?当我移动

if (this.city) {
      this.city.country.subscribe((country) => {
        console.log(country);
      }, () => {
        console.log('finished');
      }, (error) => {
        console.log(error);
      });
    }
Run Code Online (Sandbox Code Playgroud)

进入 onItemClick() 事件,它也从未从 .subscribe 返回。

* 更新 *

删除主页上国家/地区的显示,效果很好。问题似乎是您不能多次订阅 Firestore observable。即它不会重新运行查询,它只会让您等待下一个永远不会出现的项目。