[英]createUserWithEmailAndPassword error whit Reactive forms
I used ngModel before and everything was fine. 我之前使用ngModel,一切都很好。 Now I am using Reactive form to create a user in Firebase.
现在,我正在使用Reactive表单在Firebase中创建用户。
My question is how can I access the values of each field, since it marks me the following error: createUserWithEmailAndPassword failed: First argument" email "must be a valid string
我的问题是如何访问每个字段的值,因为它标记了以下错误:
createUserWithEmailAndPassword failed: First argument" email "must be a valid string
component.html component.html
<form [formGroup]="forma" (ngSubmit)="nuevoUsuario()" novalidate>
<mat-form-field appearance="outline">
<mat-label>E-mail</mat-label>
<input type="email" matInput placeholder="Ingresa tu E-mail" formControlName="email">
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Contraseña</mat-label>
<input type="password" matInput placeholder="Genera tu contraseña" formControlName="password">
</mat-form-field>
<button type="submit" class="btn btn-lg btn-primary btn-block mt-3" [disabled]="!forma.valid" >Crear cuenta <i class="fas fa-user-plus ml-2"></i></button>
</form>
component.ts component.ts
email: any;
password: string;
constructor(private fb: FormBuilder, public router: Router, public authService: FirebaseService) {
this.forma = fb.group ({
email: [ 'xxx@xxx.com', [Validators.required, Validators.email] ],
password: [ 'xxx', Validators.required ],
})
}
nuevoUsuario() {
firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
.then(userData => {
userData.sendEmailVerification();
this.router.navigate(['/ingresar']);
console.log(userData)
})
.catch(err => {
console.log(err)
});
}
我已经通过以下方式访问解决了它:
firebase.auth().createUserWithEmailAndPassword(this.forma.value.email, this.forma.value.password)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.