我用下面的登錄方法數據庫: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