Хочу получить данные из firestore в мое приложение ionic 4 - PullRequest
0 голосов
/ 26 июня 2019

Мне удалось загрузить некоторые данные в мою учетную запись в пожарном депо, но я не могу получить или прочитать данные.Я новичок и буду признателен, если буду вести себя как новичок.

     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);
    }
  });
    });
}

1 Ответ

0 голосов
/ 26 июня 2019

В вашем bookingservice есть несколько фундаментальных ошибок, поэтому я просто переписал его для вас. Надеюсь, вы сможете узнать, что случилось, посмотрев на этот код.

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;
        });

  }


}

Дайте мне знать, если это работает.

...