我使用Angular 4,AngularFire发送数据(Firebase)
我需要获取一些数据,例如:姓名,国家/地区,带有电子邮件和密码的邮政编码。
更新后://
HTML表格:
<form #formData='ngForm' (ngSubmit)="onSubmit(formData)">
<input type="text" placeholder="Name" (ngModel)="name" name="name" class="txt" required>
<input type="text" placeholder="Country" (ngModel)="country" name="country" class="txt" required>
<input type="text" placeholder="code" (ngModel)="code" name="code" class="txt" required>
<input type="text" placeholder="Email addres" (ngModel)="email" name="email" class="txt" required>
<input type="password" placeholder="Password" (ngModel)="password" name="password" class="txt" required>
<button type="submit" [disabled]="!formData.valid" class="basic-btn">Create Account</button>
</form>
我使用模型获取值并使用代码发送它:
constructor(private router: Router, private db: AngularFireDatabase) {}
onSubmit(formData) {
if(formData.valid) {
console.log(formData.value);
this.db.auth.createUser({
email: formData.value.email,
password: formData.value.password
}).then (
(state: AngularFireAuth) => {
this.db.object('/users/' + state.uid).set({code: formData.value.code});
this.router.navigate(['/login'])
}).catch(
(err) => {
console.log(err);
this.error = err;
})
}
}
我得到错误: datebase没有auth,FireAuth也没有createUser this.db.auth.createUser
此时没有uid比例^^ this.db.object('/ users /'+ state.uid).set({code:formData.value.code});
答案 0 :(得分:3)
无法在Firebase的auth部分保存额外数据。您可以使用与身份验证部分相同的uid将所有额外信息保存在数据库本身的用户下。
constructor(private db: AngularFireDatabase) {}
onSubmit(formData) {
if(formData.valid) {
console.log(formData.value);
this.af.auth.createUser({
email: formData.value.email,
password: formData.value.password
}).then (
(state: FirebaseAuthState) => {
db.object('/users/' + state.uid).set({zip: formData.value.zip});
this.router.navigate(['/login'])
}).catch(
(err) => {
console.log(err);
this.error = err;
})
}
}