Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularFire2错误“;ReferenceError:未定义firebase";_Javascript_Angular_Firebase_Firebase Authentication_Angularfire2 - Fatal编程技术网

Javascript AngularFire2错误“;ReferenceError:未定义firebase";

Javascript AngularFire2错误“;ReferenceError:未定义firebase";,javascript,angular,firebase,firebase-authentication,angularfire2,Javascript,Angular,Firebase,Firebase Authentication,Angularfire2,我正在尝试使用AngularFire2创建具有电子邮件/密码的用户 这是我在注册组件中单击提交按钮时引发错误的代码: firebase.auth().createUserWithEmailAndPassword(this.signupForm.value.email, this.signupForm.value.password).catch(function(error) { alert(error.message); }); package.json的版本: angular: "^2.

我正在尝试使用AngularFire2创建具有电子邮件/密码的用户

这是我在注册组件中单击提交按钮时引发错误的代码:

firebase.auth().createUserWithEmailAndPassword(this.signupForm.value.email, this.signupForm.value.password).catch(function(error) {
  alert(error.message);
});
package.json的版本:

angular: "^2.3.1",
"angularfire2": "^2.0.0-beta.7",
"firebase": "^3.6.6"
我从一开始就在angularfire2中实现电子邮件/传递身份验证时遇到困难,我已经搜索了一个半小时,寻找这个问题的答案(除其他外,angularfire2似乎还没有太多的信息/支持?)

请帮忙! 我仍在学习,这确实让我感到困惑

以下是控制台中的完整错误:

vendor.bundle.js:46373 ReferenceError: firebase is not defined
at SignupComponent.webpackJsonp.806.SignupComponent.signup        (http://localhost:4200/main.bundle.js:601:9)
at CompiledTemplate.proxyViewClass.View_SignupComponent0.handleEvent_0 (/AppModule/SignupComponent/component.ngfactory.js:152:34)
at CompiledTemplate.proxyViewClass.<anonymous> (http://localhost:4200/vendor.bundle.js:65473:37)
at SafeSubscriber.schedulerFn [as _next] (http://localhost:4200/vendor.bundle.js:79924:36)
at SafeSubscriber.__tryOrUnsub (http://localhost:4200/vendor.bundle.js:52413:16)
at SafeSubscriber.next  (http://localhost:4200/vendor.bundle.js:52362:22)
at Subscriber._next (http://localhost:4200/vendor.bundle.js:52315:26)
at Subscriber.next (http://localhost:4200/vendor.bundle.js:52279:18)
at EventEmitter.Subject.next (http://localhost:4200/vendor.bundle.js:52079:25)
at EventEmitter.emit (http://localhost:4200/vendor.bundle.js:79898:76)
at FormGroupDirective.onSubmit (http://localhost:4200/vendor.bundle.js:81620:23)
at Wrapper_FormGroupDirective.handleEvent (/ReactiveFormsModule/FormGroupDirective/wrapper.ngfactory.js:42:34)
at CompiledTemplate.proxyViewClass.View_SignupComponent0.handleEvent_0 (/AppModule/SignupComponent/component.ngfactory.js:150:42)
at CompiledTemplate.proxyViewClass.<anonymous> (http://localhost:4200/vendor.bundle.js:65473:37)
at HTMLFormElement.<anonymous> (http://localhost:4200/vendor.bundle.js:34579:53)
vendor.bundle.js:46373参考错误:未定义firebase
在SignupComponent.webpackJsonp.806.SignupComponent.signup(http://localhost:4200/main.bundle.js:601:9)
在CompiledTemplate.proxyViewClass.View_SignupComponent0.handleEvent_0(/AppModule/SignupComponent/component.ngfactory.js:152:34)
在CompiledTemplate.proxyViewClass上。(http://localhost:4200/vendor.bundle.js:65473:37)
在SafeSubscriber.schedulerFn[作为下一步](http://localhost:4200/vendor.bundle.js:79924:36)
在保险箱订户处(http://localhost:4200/vendor.bundle.js:52413:16)
在下一站(http://localhost:4200/vendor.bundle.js:52362:22)
在订户处。\u下一步(http://localhost:4200/vendor.bundle.js:52315:26)
在下一站(http://localhost:4200/vendor.bundle.js:52279:18)
在EventEmitter.Subject.next(http://localhost:4200/vendor.bundle.js:52079:25)
在EventEmitter.emit(http://localhost:4200/vendor.bundle.js:79898:76)
在FormGroupDirective.onSubmit(http://localhost:4200/vendor.bundle.js:81620:23)
在Wrapper_FormGroupDirective.handleEvent(/ReactiveFormsModule/FormGroupDirective/Wrapper.ngfactory.js:42:34)
在CompiledTemplate.proxyViewClass.View_SignupComponent0.handleEvent_0(/AppModule/SignupComponent/component.ngfactory.js:150:42)
在CompiledTemplate.proxyViewClass上。(http://localhost:4200/vendor.bundle.js:65473:37)
在HTMLFormElement。(http://localhost:4200/vendor.bundle.js:34579:53)

您安装了firebase吗

npm install firebase --save
我知道这是angularfire2软件包的一个依赖项。但是你的脚本没有找到它

希望您了解并解决以下问题:

您可以使用AngulareFire创建具有电子邮件/密码的用户,例如:

import { Component } from '@angular/core';
import { AngularFire, AuthProviders, AuthMethods, AngularFireModule } from 'angularfire2';
@Component({
        ...
    })
export class MyApp {
    constructor(af: AngularFire) {
    this.af.auth.createUser({ email: email, password: password})
        .then ((user) => {
            console.log(user);
        })
        .catch((error) => {        
            console.log(error);
            });

    }
}
如果要使用firebase,请尝试在导入部分的正下方声明变量
firebase

var firebase=require(“firebase”);// 因此,问题是:

我最终修改了这段代码:

firebase.auth().createUserWithEmailAndPassword(this.signupForm.value.email, this.signupForm.value.password).catch(function(error) {                    
  alert(error.message);
});

this.af.auth.createUser(this.signupForm.value).catch(function(error) {
  alert(error.message);
});
问题在于我调用了错误的对象,
firebase
,而我本应调用
this.af.auth
,正如我在构造函数中定义的
public af:AngularFire

还有另一个错误,那就是我在angularfire2模块上调用了错误的方法

我曾经

.createUserWithEmailAndPassword(电子邮件:电子邮件,密码:密码)

当我应该使用

.createUser({email,password})

修复这两个问题使应用程序按预期工作,没有错误

@sugarme是正确的答案,在我离开学校之前,我碰巧得出了相同的结论,所以直到现在我才有时间发布这个答案

谢谢大家

PS这是我完整的
注册。组件
供参考:

import { Component, OnInit } from '@angular/core';
import { AngularFire } from 'angularfire2';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';

@Component({
  selector: 'app-signup',
  templateUrl: './signup.component.html',
  styleUrls: ['./signup.component.scss']
})
export class SignupComponent {

  public signupForm = this.fb.group({
    email: [""],
    password: [""]
  });
  constructor(private router: Router, public fb: FormBuilder, public af: AngularFire) {}
  signup() {
    console.log(this.signupForm.value);
    this.af.auth.createUser(this.signupForm.value).catch(function(error) {
      alert(error.message);
    });
    this.router.navigate(['store'])
  }
}

正确地说,您没有将firebase导入页面

import { FirebaseProvider } from '../../providers/firebase/firebase';
import firebase from 'firebase';

请同时发布您收到的错误。1。是的,我已经安装了firebase,我刚刚重新安装只是为了三重检查,同样的错误。2.我已经研究过这个问题,但它并没有解决我的问题。3.早些时候,Google auth与firebase配合使用,使用命令
af.auth.login()
但您不使用
firebase
全局命令是的,我添加了一个答案,解释了我是如何让它工作的,以及问题最终是什么