我正在尝试获取创建文档的确切时间。
为此,我正在使用以下导入
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”
我不知道我是否导入了错误的库,在此先感谢您的帮助!
答案 0 :(得分:1)
您正在使用以下软件包@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