• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

question-closed Wypisywanie danych użytkownika z bazy firebase po ID- Angular 4

Cloud VPS
0 głosów
405 wizyt
pytanie zadane 8 listopada 2017 w JavaScript przez Perkos Początkujący (290 p.)
zamknięte 8 listopada 2017 przez Perkos

Witam,

Mam problem z wypisaniem danych przypisanych użytkownikowi. Użytkownik tworzy obiekt, który zawiera jego ID:

service.ts

  restaurantsCol: AngularFirestoreCollection<Restaurant>
  restaurants: any;

  restaurantDoc: AngularFirestoreDocument<Restaurant>;
  restaurant: Observable<Restaurant>

  userId: string;

constructor(private afs: AngularFirestore, private afAuth: AngularFireAuth) {
    this.afAuth.authState.subscribe(user => {
      if(user) this.userId = user.uid;
    })
   }
   getSnapshot() {
    return this.restaurants = this.restaurantsCol.snapshotChanges().map(actions => {
      return actions.map(a => {
          const data = a.payload.doc.data() as Restaurant;
          const id = a.payload.doc.id;
          return { id, data };
        })
      })
    }
    getRestaurant(userId) {
      this.restaurantsCol = this.afs.collection('restaurants', ref => ref.where('userId', '==', userId));
       return this.restaurant = this.restaurantDoc.valueChanges();

    }
    getUserId() {
      return this.userId;
    }

 

component.ts

  constructor(private restaurantService: RestaurantService) { }

  ngOnInit() {
    this.userId = this.restaurantService.getUserId();
    console.log('User ID ' + this.userId);
    this.rests = this.restaurantService.getRestaurant(this.userId);

  }
  deleteRest(id) {
    this.restaurantService.deleteRestaurant(id);
  }

Przy próbie uruchomienia wyskakuje mi taki błąd: 

Będę wdzięczny za wszelkie uwagi.
Pozdrawiam

komentarz zamknięcia: Problem rozwiązany

1 odpowiedź

0 głosów
odpowiedź 8 listopada 2017 przez Perkos Początkujący (290 p.)

Błąd był w kodzie :

getRestaurant(userId) {
      this.restaurantsCol = this.afs.collection('restaurants', ref => ref.where('userId', '==', userId));
      
 return this.restaurants = this.restaurantsCol.valueChanges();
 
    }
    getUserId() {
      return this.userId;
    }

 

Podobne pytania

0 głosów
0 odpowiedzi 143 wizyt
pytanie zadane 30 października 2017 w JavaScript przez Perkos Początkujący (290 p.)
0 głosów
1 odpowiedź 1,427 wizyt
pytanie zadane 26 listopada 2017 w JavaScript przez Kazuhiro Użytkownik (910 p.)
0 głosów
0 odpowiedzi 286 wizyt
pytanie zadane 4 sierpnia 2020 w Inne języki przez Jakub 0 Pasjonat (23,120 p.)

93,460 zapytań

142,454 odpowiedzi

322,724 komentarzy

62,838 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Kursy INF.02 i INF.03
...