【发布时间】:2021-04-14 03:38:12
【问题描述】:
我想在 firbase 中保存用户选择的日期时间(使用 ion-datetime)作为时间戳。 现在,不幸的是,firebase 将日期保存为字符串。
采摘日期和时间:
<ion-item>
<ion-label>Fälligkeits Um</ion-label>
<ion-datetime [(ngModel)]="timestamp" displayFormat="DD.MM.YYYY HH:mm" placeholder="Select Date"></ion-datetime>
</ion-item>
初始化:
export class CreateToDoPage implements OnInit {
titel = ""
label = ""
timestamp = ""
constructor(public afAuth: AngularFireAuth, private router: Router, public afStore: AngularFirestore) { }
ngOnInit() {
}
保存到 Firebase:
async createToDo() {
const { titel, label, timestamp } = this;
try {
const user = await this.afAuth.currentUser;
await this.afStore.collection("/user/" + user.uid + "/todos").add({ name: titel, label: label, due: timestamp }).then((f) => { console.log(f) }).catch((error) => { console.dir(error) });
} catch (error) {
console.dir(error);
}
}
我已经试过设置变量timestamp的类型了:
timestamp: AngularFirestore.timestamp = ""
但是我得到了这个错误:
[ts] 'AngularFirestore' 仅指一种类型,但被用作 命名空间在这里。
如果您有任何想法,我将不胜感激:)
【问题讨论】:
标签: angular firebase datetime ionic-framework google-cloud-firestore