我用下面的登录方法数据库:Angularfire2新用户添加到
login() {
this.auth.login();
this.authService.login().subscribe(() => {
if (this.authService.isLoggedIn) {
console.log("ADDING THE USER..");
// Add a new user to the users table
this.af.child("users").child(this.authService.userData.uid).set({
provider: this.authService.userData.provider,
name: this.getName(this.authService.userData)
});
// Redirect the user
this.router.navigate(['/panel']);
}
});
}
几乎相同的文档中的方法:https://www.firebase.com/docs/web/guide/user-auth.html#section-storing
当我运行我的应用程序,我收到以下错误:
Property 'child' does not exist on type 'AngularFire'.
并且未添加用户。怎么了?
我需要的仅仅是添加一个新对象到我的Firebase数据库。 下面的作品,但我需要如上所示的结构:
this.users = this.af.database.list('/users');
this.users.push("TEST");
所以,我怎么能使用https://www.firebase.com/docs/web/guide/user-auth.html#section-storing相同的结构添加新的用户对象到我的数据库?以及为什么我不能运行我的代码,如果它与记录相同?
更新
我的新代码:
this.af.database.object('/users/${this.authService.userData.uid}').set({
provider: this.authService.userData.provider,
name: this.getName(this.authService.userData)
});
- 没有用户插入(我的火力数据库是空的)
https://github.com/angular/angularfire2/blob/master/docs/2-retrieving-data-as-objects.md#api-summary – cartant