最近:
角度: 5.2
Firebase SDK: 4.13.0
国家预防机制: 6.0.0
节点: v8.11.1
试图使用以下代码创建具有防火墙的用户注册:
signup.component.html:
<form (ngSubmit)="onSignup(form)" #form="ngForm">
<div class="form-group">
<label for="email">Email</label>
<input name="email" id="email" type="email" class="form-control" ngModel>
</div>
<div class="form-group">
<label for="Password">Password</label>
<input name="Password" id="Password" type="text" class="form-control" ngModel>
</div>
<button type="submit" class="btn btn-success">Sign Up</button>
</form>signup.component.ts:
import { Component, OnInit } from '@angular/core';
import {NgForm} from '@angular/forms';
import {AuthService} from '../auth.service';
@Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.css']
})
export class SignupComponent implements OnInit {
constructor(private authService: AuthService) { }
ngOnInit() {
}
onSignup(form: NgForm) {
const email = form.value.email;
const password = form.value.password;
this.authService.signupUser(email, password);
}
}在AuthService.service.ts中:
import * as firebase from 'firebase';
import {Injectable} from '@angular/core';
import {Router} from '@angular/router';
@Injectable()
export class AuthService{
token: string;
constructor(private router: Router) {}
signupUser(email: string, password: string) {
firebase.auth().createUserWithEmailAndPassword(email, password)
.catch(
error => console.log(error)
);
}}但是,当我单击“注册”按钮时,它仍然会在控制台上抛出此错误:
ERROR
N {code: "auth/argument-error", message: "createUserWithEmailAndPassword failed: Second argument "password" must be a valid string.", ngDebugContext: DebugContext_, ngErrorLogger: ƒ}
code:
"auth/argument-error"
message:
"createUserWithEmailAndPassword failed: Second argument "password" must be a valid string."那么,是否有可能使用此方法使用firebase创建一个新用户?!
发布于 2018-05-07 04:40:36
SDK是正确的,看起来您的HTML中有一个错误。
<input name="Password" id="Password" type="text" class="form-control" ngModel>
id和name都是大写属性Password,但在signupUser函数中,您正在尝试访问小写属性password。
尝试将HTML更新为<input name="password" id="password" type="text" class="form-control" ngModel>
https://stackoverflow.com/questions/50205711
复制相似问题