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
Ionic framework 想从firestore获取数据到我的ionic 4应用程序吗_Ionic Framework_Google Cloud Firestore_Modal Dialog_Ionic4 - Fatal编程技术网

Ionic framework 想从firestore获取数据到我的ionic 4应用程序吗

Ionic framework 想从firestore获取数据到我的ionic 4应用程序吗,ionic-framework,google-cloud-firestore,modal-dialog,ionic4,Ionic Framework,Google Cloud Firestore,Modal Dialog,Ionic4,我可以将一些数据上传到我的firestore帐户,但我无法获取或读取数据。我是新手,如果我像新手一样被引导,我会很感激的 ngOnInit() { this.bookingservice.read_AcBookings().then(data => this.booking = data.map(e => { return { id: e.payload.doc.id, isEdit: false, // tsl

我可以将一些数据上传到我的firestore帐户,但我无法获取或读取数据。我是新手,如果我像新手一样被引导,我会很感激的

     ngOnInit() {
    this.bookingservice.read_AcBookings().then(data =>
     this.booking = data.map(e => {
      return {
        id: e.payload.doc.id,
        isEdit: false,
// tslint:disable-next-line: no-string-literal
        firstname: e.payload.doc.data()['firstname'],
// tslint:disable-next-line: no-string-literal
        lastname: e.payload.doc.data()['lastname'],
// tslint:disable-next-line: no-string-literal
        phonenumber: e.payload.doc.data()['phonenumber'],
// tslint:disable-next-line: no-string-literal
        address: e.payload.doc.data()['address'],
// tslint:disable-next-line: no-string-literal
        location: e.payload.doc.data()['location'],
// tslint:disable-next-line: no-string-literal
        date: e.payload.doc.data()['date'],
// tslint:disable-next-line: no-string-literal
        servicebooked: e.payload.doc.data()['servicebooked'],

      };
    }));
    console.log(this.booking);

  }
这就是服务

 read_AppliancesBookings() {
  return new Promise<any>((resolve, reject) => {
    this.afAuth.user.subscribe(currentUser => {
    if (currentUser) {
this.snapshotChangesSubscription = this.firestore.collection('Bookings').doc(currentUser.uid).collection('Appliances Bookings')
.snapshotChanges();
resolve(this.snapshotChangesSubscription);
    }
  });
    });
}
read_AppliancesBookings(){
返回新承诺((解决、拒绝)=>{
this.afAuth.user.subscribe(currentUser=>{
如果(当前用户){
this.snapshotChangesSubscription=this.firestore.collection('Bookings').doc(currentUser.uid).collection('Appliances Bookings'))
.snapshotChanges();
解决(此快照更改订阅);
}
});
});
}

在您的
预订服务中有一些基本错误,所以我只是为您重写了它。希望通过查看此代码,您可以了解出了什么问题

import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
import { reject } from 'q';

@Injectable({
  providedIn: 'root'
})
export class bookingservice {

  constructor(public afAuth: AngularFireAuth, public firestore: AngularFirestore) { }

  userId = this.afAuth.auth.currentUser.uid;

  read_AppliancesBookings() {

        return new Promise((resolve, reject) => {
          this.firestore
            .doc<any>(`Bookings/${userId}`)
            .valueChanges()
            .subscribe(doc => {
              resolve(doc);
            });
        }).then((result) => {
          return result;
        });

  }


}
从'@angular/core'导入{Injectable};
从'@angular/fire/auth'导入{AngularFireAuth};
从'@angular/fire/firestore'导入{AngularFirestore};
从'q'导入{拒绝};
@注射的({
providedIn:'根'
})
导出类预订服务{
构造函数(公共afAuth:AngularFireAuth,公共firestore:AngularFirestore){}
userId=this.afAuth.auth.currentUser.uid;
read_AppliancesBookings(){
返回新承诺((解决、拒绝)=>{
这是消防商店
.doc(`Bookings/${userId}`)
.valueChanges()
.订阅(doc=>{
解决(doc);
});
})。然后((结果)=>{
返回结果;
});
}
}

让我知道这是否有效。

console.log(this.booking)的输出是什么?未定义的结果和data.map不是函数