【问题标题】:Property 'firestore' does not exist on type 'Firebase'“Firebase”类型上不存在属性“firestore”
【发布时间】:2020-05-01 13:07:39
【问题描述】:

我正在尝试获取文档创建的确切时间。

为此,我使用以下导入

import { Firebase } from '@ionic-native/firebase/ngx';
import { AngularFirestore } from '@angular/fire/firestore';
import { AngularFirestore } from '@angular/fire/firestore';

我的构造函数如下。

constructor(private aF: AngularFireStore, private firebase: Firebase, private cS: CartService, private ui: UiService){}

这是我尝试添加时间戳的方法。

    checkout2() {
    const pickup = this.pickup;
    const deliveryname = this.deliveryname;
    const location = this.location;
    const note = this.note;
    const deliverystate = this.deliverystate;
    const cart = this.cS.getCart();
    const total = this.getTotal();
    const uid = this.aS.getInfo();
    return new Promise<any>((resolve, reject) => {
      this.aF.collection('/ordenes').add({
        cart,
          pickup,
          location,
          deliveryname,
          createdAt: this.firebase.firestore.Timestamp.fromDate(new Date()),
          note,
          total,
          deliverystate,
          uid
      })
      .then(
        (res) => {
          resolve(res);
          this.cS.cleanCart();
          this.cS.cleanItemCount();
          this.close();

        },
        err => reject(err)
      );
    });
  }

我收到一条错误消息:

“Firebase”类型上不存在属性“firestore”

我不知道我是否导入了错误的库,提前感谢您的帮助!

【问题讨论】:

    标签: angular firebase ionic-framework google-cloud-firestore


    【解决方案1】:

    这是我用 typescript 初始化 firebase 和 firestore

    import { initializeApp } from 'firebase/app';
    import { initializeFirestore } from 'firebase/firestore'
    import config from "./config";
    
    const fb = initializeApp(config.firebaseConfig);
    const db = initializeFirestore(fb, {})
    
    export default fb;
    

    【讨论】:

      【解决方案2】:

      您正在使用以下包@ionic-native/firebase/ngx,其中不包含与firestore 相关的任何内容。您可以在以下链接中找到该包的 api:

      https://github.com/arnesson/cordova-plugin-firebase/blob/master/docs/API.md

      你需要初始化firestore,然后你就可以使用上面的方法,查看这里了解更多信息:

      https://cloud.google.com/firestore/docs/quickstart-mobile-web#set_up_your_development_environment

      【讨论】:

        猜你喜欢
        • 2020-10-06
        • 2017-10-17
        • 1970-01-01
        • 2018-01-12
        • 2019-03-24
        • 1970-01-01
        • 2019-01-21
        • 1970-01-01
        • 2021-01-09
        相关资源
        最近更新 更多