Angular 4注册firebase第一个参数“email”必须是有效的字符串

时间:2017-07-22 13:39:37

标签: angular typescript firebase

控制台给出了以下错误:

enter image description here

我已经尝试过在Google上找到的多种解决方案,但它仍然无效。

import { Component, OnInit } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';

@Component({
  selector: 'app-signup',
  templateUrl: './signup.component.html'
})
export class SignupComponent implements OnInit {

  constructor() { }

  signUp(email: string, password: string){
    firebase.auth().createUserWithEmailAndPassword(email, password)
    .catch(function(error:any) {
    // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
    });
  }

  ngOnInit() {
  }

}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Javascript类型可能有问题。 Firebase Auth要求参数类型为string。 Observables,String Object和其他类似字符串的对象实际上不是string的类型。

typeof new String("email@email.io")  // "object"
typeof String(new String("email@email.io"))  // "string"
typeof "email@email.io"  // "string"

您可以尝试这样的事情:

firebase.auth().createUserWithEmailAndPassword(String(email), String(password))