2016-10-17 3 views
1

데이터베이스에 새 사용자를 추가 :는 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) 
      }); 
없음 사용자가 삽입되지
  • (내 중포 기지 데이터베이스가 비어)
+0

https://github.com/angular/angularfire2/blob/master/docs/2-retrieving-data-as-objects.md#api-summary – cartant

답변

4

사용 object(); 자식() 존재하지 않습니다 :

this.af.database.object(`users/${this.authService.userData.uid}`).set({...}) 
+0

쿨 하나, 감사합니다. 그러나'.af' 다음에'.database'를 추가하는 것을 잊었습니다. 어쨌든, 왜 내 데이터베이스에 아무 것도 추가되지 않는다. 업데이트 내 코드 – TheUnreal

+0

오류가 발생합니까? 보안 규칙은 괜찮습니까? – Sasxa

+0

오류가 발생하지 않습니다. 내 rulese은'{ "규칙": { ".read": "true"로, "에 .write": "true"로 은} 은}'내 중포 기지 데이터베이스 콘솔에서 난 단지'null' – TheUnreal

0

이 하나는 짧은 버전입니다.

import { AngularFireDatabase } from "angularfire2"; 

... 

constructor(private afd: AngularFireDatabase) {} 

... 

this.afd.object(`users/${this.authService.userData.uid}`).set({...});