【发布时间】:2018-05-06 18:35:36
【问题描述】:
我想创建一个能够在 firebase 中进行身份验证的用户,然后将用户的数据插入数据库中。 我使用的代码如下:
this.app.auth().createUserWithEmailAndPassword(userForm.value.email, userForm.value.password)
.then(res => {
console.log('2 form data:', userForm.value);
this._firebase.app.database().ref('users').push({
email: userForm.value.email,
uid: res.uid
})
})
.catch(err => {
console.log('Something went wrong:', err.message);
});
我使用app 将用户插入authentication 和_firebase 将用户的数据插入database。 createUserWithEmailAndPassword 有效,但出现以下错误:
Reference.push failed: first argument contains undefined in property 'users.email'
userForm 包含用户数据。有什么问题?
【问题讨论】:
-
如果在 this._firebase.app.database().ref 之前执行 console.log({ email: userForm.value.email, uid: res.uid }) 在控制台中会看到什么('users').push ??
-
我看到这个: Object { email: undefined, uid: "hguE4Qnh0VN0NI4NWlDr188A8Xt2" } 电子邮件未定义,因此所有表单数据都未定义。有什么解决办法吗?
-
您的电子邮件值未定义,因此您收到错误消息。您应该从表单中获得正确的值。您可能会遵循 Muiz Mahdy 的回答。 (我没有 Angular 的资格,很抱歉我帮不上忙)
-
似乎在 .then({}) 中所有的表单数据都是未定义的。这怎么可能?表单中给出的电子邮件和密码被插入到身份验证中
-
你试过 Muiz Mahdy 的回答吗?
标签: angular firebase firebase-realtime-database