使用angularfire2从Firebase接收数据时。一切都可以在浏览器中运行,但结果不会仅在真实设备中的离子视图中显示

时间:2019-04-05 12:15:43

标签: javascript firebase ionic-framework google-cloud-firestore angularfire2

虽然使用angularfire2从Firebase数据库中获取数据时,新数据不会在真实设备离子视图中实时更新,但在浏览器中可以正常运行。

我尝试使用NgZone,但没有用。搜索谷歌,但没有解决方案。

constructor(
    public ng_zone: NgZone,
    public geolocation: Geolocation,
    public db: AngularFirestore,
  ) {
    this.itemsCollection = db.collection<Item>('locations');
    this.items = this.itemsCollection.snapshotChanges(['added', 'modified']).pipe(
      map(actions => actions.map(a => {
        const data = a.payload.doc.data() as Item;
        const id = a.payload.doc.id;
        console.log(a.payload.doc.data());

        this.ng_zone.run(() => {
          this.lat = a.payload.doc.get('latitude');
          this.lng = a.payload.doc.get('longitude');
        });

        this.docID = id;
        console.log(this.docID + " my id");
        return { id, ...data };
      }))
    );
  }

问题仅在浏览器应用程序的真实设备中可以正常运行。在控制台中的android real device中,我得到结果,但不在视图中。我想在实时设备离子视图中实时显示更新的纬度和经度。

0 个答案:

没有答案