【发布时间】:2017-09-27 15:12:05
【问题描述】:
目前正在研究https://github.com/codediodeio/angular-firestarter这个repos认证。
这个sn-p将用户名和email写入实时数据库,在这个repo的Authentication服务中,作者使用这个方法在用户每次注册和登录时更新用户数据。
//// Helpers ////
private updateUserData(): void {
// Writes user name and email to realtime db
// useful if your app displays information about users or for admin features
const path = `users/${this.currentUserId}`; // Endpoint on firebase
const data = {
email: this.authState.email,
name: this.authState.displayName
}
this.db.object(path).update(data)
.catch(error => console.log(error));
}
在我目前正在进行的副项目中,我使用上面的 sn-p 将用户详细信息写入 firebase,仅在注册时用户详细信息(不仅是电子邮件和通行证)与他在 repo 中使用 sn- p 还可以在登录和注册时更新用户详细信息。
在一行
this.db.object(path).update(data)
我的文档https://github.com/angular/angularfire2/blob/master/docs/2-retrieving-data-as-objects.md#api-summary 有两种类似的方法,.update() 和set(),它在文档中说.update() 是非破坏性更新 和set() 破坏性更新。我试过这两个,它的工作原理和另一个一样,
我的问题是,正如我在上面解释的那样,我只在注册时使用 sn-p,我应该使用 set() 或 update() 什么?以及什么是破坏性和非破坏性更新,链接说明这些有什么大帮助。
【问题讨论】:
标签: angular firebase angularfire2