Angularfire依赖项注入-Cartservice类型上不存在TS2339属性Firestore

问题描述

我正在把angularefire添加到angular.io“看一下教程”(购物车)。尝试使用Firebase Firestore替换product.ts和shipping.json,并编写一个替换“您的订单已提交”的forders文件。可以,但是....

在cart.service.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
//angularfire
import { AngularFirestore} from '@angular/fire/firestore';
import { Observable } from 'rxjs';

@Injectable()
export class CartService {

  items = [];
//angularfire
  fshipping: Observable<any[]>;
  afs: AngularFirestore;

  constructor(
    private http: HttpClient,//angularfire
    firestore: AngularFirestore
  ) { 
    this.fshipping = firestore.collection('fshipping').valueChanges();
    this.afs = firestore;
  }

  addToCart(product) {
    this.items.push(product);
  }
  getItems() {
    return this.items;
  }

  clearCart() {
    this.items = [];
    return this.items;
  }

  getShippingPrices() {
//angularfire
    // return this.http.get('/assets/shipping.json');
    return this.fshipping;
  }

//angularfire
  placeOrder(customerData) {
    const orderColl = this.afs.collection<any>('forders');
//    const orderColl = this.firestore.collection<any>('forders');
    orderColl.add({
      name: customerData.name,address: customerData.address
    });
  }

}

fshipping(在构造函数内部)起作用并替换了shipping.json。 但是在placeOrder方法中,我必须使用this.afs.collection('forders')...如果使用this.firestorre.collection ....出现以下错误

src / app / cart.service.ts:45:28中出现错误-错误TS2339:类型“ CartService”上不存在属性“ firestore”。

第45行:

const orderColl = this.firestore.collection<any>('forders');

研究其他在线教程时,他们可以使用通过构造函数注入的firestore以其他方法使用。我错过了什么?谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)