2

我試圖創建一個使用AngularFire2AngularFire2錯誤「的ReferenceError:火力點沒有定義」

這是引發錯誤的代碼與電子郵件/密碼的用戶,當我點擊我的註冊組件的提交按鈕:

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" 

我一直有麻煩實現電子郵件/通AUTH從一開始就angularfire2,我已經搜查˚F或超過一個半小時尋找這個問題的答案(其中,似乎沒有很多的信息/支持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) 
+0

也請張貼你的錯誤。 –

+0

我加了 –

回答

1

您可以使用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); 
      }); 

    } 
} 

如果你想使用火力點,然後再嘗試在您的導入部分正下方聲明變量firebasevar firebase = require("firebase"); // <-- Declare firebase variable here

它在我的工作組件中。讓我知道結果。

+0

是的,我添加了一個解釋我得到它的工作和問題最終成爲了什麼 –

0

你安裝火力?

npm install firebase --save 

我知道這是angularfire2軟件包的依賴關係。但是你的腳本沒有找到它。

願你有一個瞭解和解決的問題: https://github.com/angular/angularfire2/issues/520

+0

以上1.是的,我安裝了firebase,我只是重新安裝了三重檢查,同樣的錯誤。 2.我已經看過這個問題,它並沒有解決我的問題。 3.使用firebase的Google auth在早些時候工作得很好,使用命令'af.auth.login();'但是您不使用該命令的'firebase'全局 –

2

那麼,是什麼原來是這個問題如下:

我結束了修訂這個的代碼塊:

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(email: email, password: password)

什麼時候應該」已經使用

.createUser({email, password})

解決這兩個問題使應用程序按預期工作,沒有錯誤。

@sugarme是正確答案,我只是碰巧得出了同樣的結論之前,我離開學校,所以我沒有時間發佈這個答案直到現在。

謝謝大家!

PS這裏是我的全signup.component以供參考:

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']) 
    } 
} 
相關問題