我在下面有这个代码,我正在尝试存储用户的注册信息,以便能够将其存储到firebase的新角度火焰中。我试图将电子邮件变量存储在@ViewChild中,并且收到错误“createUserWithEmailAndPassword failed:First argument \”email \“必须是有效的字符串。”我该如何解决这个问题?
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import { LoginPage } from '../login/login';
/**
* Generated class for the RegisterPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-register',
templateUrl: 'register.html',
})
export class RegisterPage {
//Variables
fName = " ";
lName = " ";
//email = " ";
//password = " ";
gender = " ";
constructor(private fire: AngularFireAuth,public navCtrl: NavController, public navParams: NavParams)
{}
ionViewDidLoad() {
console.log('ionViewDidLoad RegisterPage');
}
//ViewChild - To get access to a component and its methods, we can use @ViewChild decorator.
@ViewChild('email') email = "";
@ViewChild('password') password = "";
registerUser() {
//var email = "myemail@email.com";
//var password = "mypassword";
this.fire.auth.createUserWithEmailAndPassword(this.email, this.password)
.catch(function(error) {
//Handles Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if(errorCode == 'auth/email-already-in-use') {
alert('The email is already in use. ');
} else {
alert(errorMessage);
}
if(errorCode == 'auth/invalid-email') {
alert('The email is not valid. ');
} else {
alert(errorMessage);
}
if(errorCode == 'auth/weak-password') {
alert('The password is not strong enough. ');
} else {
alert(errorMessage);
}
console.log(error);
this.navCtrl.push(LoginPage);
});
}
}