Ошибка: Uncaught (в обещании): TypeError: undefined не является функцией - PullRequest
0 голосов
/ 03 июля 2019

Я пытаюсь показать список автомобилей в моем html-компоненте, но он выдает эту ошибку ... Я использую Firebase

Услуги

import { Injectable } from '@angular/core';

import { AngularFirestore, AngularFirestoreCollection, 
AngularFirestoreDocument } from '@angular/fire/firestore';

import { Cars } from '../models/cars';
import { AuthService } from './auth.service';
import { ToastrService } from './toastr.service';
import { User } from '../../shared/models/user';

@Injectable()
export class BusesService {

userDetail: User;

buses: AngularFirestoreCollection<Cars>;
buse : AngularFirestoreDocument<Cars>;

constructor(
  private db: AngularFirestore,
  private authService: AuthService,
  private toastrService: ToastrService
  ) {
 }
 getBuses(){ 
   this.userDetail = this.authService.getLoggedInUser();

   this.buses = this.db.collection('cars',
   ref => ref.where('userId', '==', this.userDetail.$key));

   return this.buses;
  }
 }

Компонент, в котором я пользуюсь услугой

import { Component, OnInit } from '@angular/core';
import { Cars } from '../../../shared/models/cars';
import { AuthService } from '../../../shared/services/auth.service';
import { BusesService } from '../../../shared/services/buses.service';
import { ToastrService } from 'src/app/shared/services/toastr.service';

@Component({
 selector: 'app-lista-camiones',
 templateUrl: './lista-camiones.component.html',
 styleUrls: ['./lista-camiones.component.scss']
 })

export class ListaCamionesComponent implements OnInit {

 productList: Cars[];
 productObject: Cars;

 loading = false;

constructor(
  public authService : AuthService,
  private busesService : BusesService,
  private toastrService : ToastrService
) { }

ngOnInit() {
  this.getAllProducts();
}

  getAllProducts(){
    console.log("getting Cars");

   this.loading = true;
    const x = this.busesService.getBuses();
    x.snapshotChanges().subscribe(
      (product) => {
        this.loading = false;

        this.productList = [];
        console.log(" products" + product);

        product.forEach((element) => {

          this.productObject = element.payload.doc.data();
          this.productObject.userid = element.payload.doc.id;
          console.log("data : " + this.productObject.userid);
          this.productList.push(this.productObject as Cars);
        });
      },
      (err) => {
        this.toastrService.error('Error while fetching Car List', err);
      }
     );

    }
}

Модель

export class Cars {
   userid: string;
   driverid: number;
   unitid: string;
   description: string;
}

Error

ОШИБКА Ошибка: Uncaught (в обещании): TypeError: undefined не является Функция TypeError: undefined не является функцией в Array.map () at webpackAsyncContext (ленивый объект пространства имен $ _lazy_route_resource: 45)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...