【问题标题】:createUserWithEmailAndPassword error whit Reactive forms反应式表单的createUserWithEmailAndPassword错误
【发布时间】:2018-05-26 14:31:09
【问题描述】:

我之前使用过 ngModel,一切都很好。现在我正在使用 Reactive 表单在 Firebase 中创建用户。

我的问题是如何访问每个字段的值,因为它标记了我以下错误:createUserWithEmailAndPassword failed: First argument" email "must be a valid string

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>

组件.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)
  });
}

【问题讨论】:

    标签: javascript angular firebase firebase-authentication


    【解决方案1】:

    我已经通过这种方式访问​​解决了:

    firebase.auth().createUserWithEmailAndPassword(this.forma.value.email, this.forma.value.password)
    

    【讨论】:

      猜你喜欢
      • 2020-09-07
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2018-07-17
      • 2021-09-27
      • 1970-01-01
      相关资源
      最近更新 更多