2016-12-18 3 views
0

私はこのチュートリアルの次のとおりです:https://javebratt.com/angularfire2-email-auth/と私は奇妙なエラーが発生します。未定義はオブジェクトではありません( 'type.parameters'を評価する)

私は、ログインページの実装では、と私はすでにこの2つのファイル

login.ts

import { 
    NavController, 
    LoadingController, 
    AlertController 
} from 'ionic-angular'; 
import { Component } from '@angular/core'; 
import { FormBuilder, Validators } from '@angular/forms'; 
import { AuthData } from '../../providers/auth-data'; 

import { Page1 } from '../../pages/page1/page1'; 
import { SignupPage } from '../../pages/signup/signup'; 
import { ResetPasswordPage } from '../../pages/reset-password/reset-password'; 

import { EmailValidator } from '../../validators/email'; 


/* 
    Generated class for the Login page. 

    See http://ionicframework.com/docs/v2/components/#navigation for more info on 
    Ionic pages and navigation. 
*/ 
@Component({ 
    selector: 'page-login', 
    templateUrl: 'login.html' 
}) 
export class LoginPage { 
    public loginForm: any; 
    emailChanged: boolean = false; 
    passwordChanged: boolean = false; 
    submitAttempt: boolean = false; 
    public loading: any; 

    constructor(public nav: NavController, public authData: AuthData, 
public formBuilder: FormBuilder, public alertCtrl: AlertController, 
public loadingCtrl: LoadingController) { 
    this.loginForm = formBuilder.group({ 
     email: ['', Validators.compose([Validators.required, 
     EmailValidator.isValid])], 
     password: ['', Validators.compose([Validators.minLength(6), 
     Validators.required])] 
    }); 
    } 


    goToResetPassword(){ 
    this.nav.push(ResetPasswordPage); 
    } 

    createAccount(){ 
    this.nav.push(SignupPage); 
    } 

    ionViewDidLoad() { 
    console.log('Hello LoginPage Page'); 
    } 

    elementChanged(input){ 
    let field = input.inputControl.name; 
    this[field + "Changed"] = true; 
    } 

    loginUser(){ 
     this.submitAttempt = true; 

     if (!this.loginForm.valid){ 
     console.log(this.loginForm.value); 
     } else { 
     this.authData.loginUser(this.loginForm.value.email, 
      this.loginForm.value.password).then(authData => { 
      this.nav.setRoot(Page1); 
     }, error => { 
     this.loading.dismiss().then(() => { 
      let alert = this.alertCtrl.create({ 
      message: error.message, 
      buttons: [ 
      { 
       text: "Ok", 
       role: 'cancel' 
      } 
      ] 
      }); 
     alert.present(); 
     }); 
     }); 

     this.loading = this.loadingCtrl.create({ 
     dismissOnPageChange: true, 
     }); 
     this.loading.present(); 
     } 
    } 

} 

とのauth-data.ts

import { Injectable } from '@angular/core'; 
import 'rxjs/add/operator/map'; 

import { AngularFire } from 'angularfire2'; 


@Injectable() 
export class AuthData { 
    fireAuth: any; 
    constructor(public af:AngularFire) { 
    console.log('Hello AuthData Provider'); 
    af.auth.subscribe(user => { 
     if(user){ 
      this.fireAuth = user.auth; 
      console.log(user); 
     } 
    }) 
    } 
    loginUser(newEmail: string, newPassword: string): any { 
    return this.af.auth.login({ email: newEmail, password: newPassword }); 
    } 

    resetPassword(email: string): any { 
    return firebase.auth().sendPasswordResetEmail(email); 
    } 

    logoutUser(): any { 
    return this.af.auth.logout(); 
    } 

    signupUser(newEmail: string, newPassword: string): any { 
    return this.af.auth.createUser({ email: newEmail, password: newPassword }); 
    } 
} 

しかし、実装しています私は 'ionic serve'をします。login.tsによって次の奇妙なエラーが発生します。

Property 'loginUser' does not exist on type 'AuthData'

このloginUser関数は私のauth-data.tsにあります。その意味は分かりません。

「this.authData」は開始されませんでしたが、コンストラクタにthis.authData = authDataを追加しても、何も変更されません。 (それはまた、私はそれがどのように開始されるのか理解していないと言います)

誰かが私はこのloginUserエラーを取得する理由は知っていますか?

どうもありがとう

EDIT:あなたのアドバイスの一つに

おかげで、私は私の変更を元に戻しても、今正直に言う場合でも、(エラーが消えて、新しいものがここにあるように思えるの下に

Safariで発生するエラーは、TypeErrorです:未定義はオブジェクト(「type.parameters」と評価されます)であり、Firefoxでは:TypeError:型は未定義です[ En savoir plus]

Firefox consoルは、あなたが間違ってフォームパラメータにアクセスしているここで私はとても混乱している私に

ReflectionCapabilitieshttp://localhost:8100/build/main.js:45824:1 Reflectorhttp://localhost:8100/build/main.js:45964:16 CompileMetadataResolverhttp://localhost:8100/build/main.js:25506:38 CompileMetadataResolverhttp://localhost:8100/build/main.js:25471:21 CompileMetadataResolverhttp://localhost:8100/build/main.js:25357:51 map self-hosted CompileMetadataResolverhttp://localhost:8100/build/main.js:25356:65 RuntimeCompilerhttp://localhost:8100/build/main.js:40363:24 RuntimeCompilercompileModuleAndComponents http://localhost:8100/build/main.js:40301:32 RuntimeCompilerhttp://localhost:8100/build/main.js:40292:16 PlatformRefbootstrapModuleWithZone http://localhost:8100/build/main.js:27765:16 PlatformRefhttp://localhost:8100/build/main.js:27747:16 http://localhost:8100/build/main.js:96568:1 webpack_require http://localhost:8100/build/main.js:20:12 http://localhost:8100/build/main.js:66:18

を与え、何かが間違って開始しなければならないが、エラー・スタックが本当に助けにはならない...

+0

正しいauth-data.tsファイルをインポートしていることを確認できるように、フォルダ構造の例を拡張できますか? – Fjut

答えて

0
this.authData.loginUser(this.loginForm.value.email, 
     this.loginForm.value.password) 

。 loginUser関数には2つの文字列引数が必要です。

試してみてください。

this.loginForm.controls["email"].value 
this.loginForm.controls["password"].value 

EDIT:

resetPassword(email: string): any { 
    return firebase.auth().sendPasswordResetEmail(email); 
    } 

私は、ファイル内の任意の場所に設定されfirebaseオブジェクトを参照してくださいいけない:私はこれを推測しています2番目のエラーのため が問題です。

+0

私は助けてくれた、ありがとう、しかし今私は別のエラーがある、私は私の最初のポストを更新させてください – Krowar

+0

は、firebaseが 'anglefire2'からインポート{AngularFire}でインポートされていません。 ?それは昇華が私にエラーを投げ込まないように思われ、私が得るエラーはhtmlの右側にありますか? – Krowar

+0

あなたはそれをaf..として注入しました。他の機能でthis.af.authを使用しました –

0

My guess would have been that 'this.authData' is never initiated, but even when I add this.authData = authData in the constructor, it does not change anything. (that also says that I don't understand how it gets initiated)

角度インジェクタがプロバイダの初期化を担当するので、これを行う必要はありません。その詳細を読むことができますhere

問題については、チュートリアルに記載されているように、アプリケーションルートモジュールでプロバイダをインポートして登録しましたか?

+0

私はこれが問題だったとは思っていませんでした。そうでなければ、 'no provider for ..'エラー –

関連する問題