【问题标题】:Can not produce angular 6 timestamp, missing imports无法生成角度 6 时间戳,缺少导入
【发布时间】:2018-08-31 09:58:48
【问题描述】:

我试图在单击(按钮)时生成一个时间戳,并在单击另一个按钮时生成另一个时间戳。本质上是一个打卡钟。我了解如何创建按钮,但不知道要导入的包会产生时间戳……是的,我已经在整个网络上搜索了这个。

最终,我想为每个注册用户将其注册到 firebase db,但我们稍后会讨论。

【问题讨论】:

  • 您能否详细说明您到目前为止所尝试的具体内容以及遇到的问题?
  • in html: in ts。 file timein(//GET THE TIME//) { this.firebaseAuth .auth .timestamp(//实际时间//) .then(value => { console.log('Nice, it works!'); }) . catch(err => { console.log('出了点问题:', err.message); });注销相同。理想情况下是 HTML 中的实际时间显示
  • 你能edit你问题中的信息吗?并且可能包含一个数据库结构示例,显示您尝试保存它的位置以及您遇到的确切错误?

标签: firebase time timestamp angular6


【解决方案1】:
import * as firebase from 'firebase'

user.createdAt = firebase.firestore.FieldValue.serverTimestamp()
user.updatedAt = firebase.firestore.FieldValue.serverTimestamp()

来自文档:https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue#.serverTimestamp

【讨论】:

  • 如果是这样的话,找不到用户...嗯code user = this.afAuth.auth.currentUser; punchin() { this.user.createdAt = firebase.firestore.FieldValue.serverTimestamp() } punchout() { this.user.updatedAt = firebase.firestore.FieldValue.serverTimestamp() }
  • @SabrinaTesla 这是另一个问题。您不能将其他属性分配给 auth 用户对象 firebase.google.com/docs/auth/users
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2019-04-29
  • 1970-01-01
  • 1970-01-01
  • 2018-11-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多