簡體   English   中英

未定義不是對象(評估“ type.parameters”)

[英]Undefined is not an object (evaluating 'type.parameters')

我正在按照本教程進行操作: https : //javebratt.com/angularfire2-email-auth/ ,但出現一個奇怪的錯誤。

我正在執行登錄頁面,並且已經實現了這兩個文件

登錄名

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 });
  }
}

但是當我做“離子服務”時,我通過login.ts得到了以下奇怪的錯誤

類型“ AuthData”上不存在屬性“ loginUser”

這個loginUser函數位於我的auth-data.ts中,所以我不明白它的含義。

我的猜測是永遠不會啟動“ this.authData”,但是即使我在構造函數中添加this.authData = authData ,它也不會改變任何東西。 (這也說明我不明白它是如何啟動的)

有誰知道為什么我得到這個loginUser錯誤?

非常感謝

編輯:

感謝您在下面提供的一項建議,該錯誤似乎已經消失,並且這里出現了一個新錯誤(即使現在說實話,即使我還原更改,但仍然收到新錯誤,我都很困惑)

現在我在Safari中遇到的錯誤是TypeError:undefined不是一個對象(正在評估'type.parameters'),而在Firefox中:TypeError:type是undefined [En savoir plus]

Firefox控制台給了我

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映射自托管的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

我很困惑,必須錯誤地啟動某些內容,但錯誤堆棧並不能真正幫助您...

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

在這里您不正確地訪問表單參數。 loginUser函數需要2個字符串參數。

嘗試:

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

編輯:對於第二個錯誤,我猜這是問題所在:

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

我看不到文件中任何地方設置的firebase對象。

我的猜測是永遠不會啟動“ this.authData”,但是即使我在構造函數中添加this.authData = authData,它也不會改變任何東西。 (這也說明我不明白它是如何啟動的)

您不需要這樣做,因為角度噴射器負責提供程序的初始化。 您可以在此處了解更多信息

關於您的問題,您是否按照教程中所述在應用程序根模塊中導入並注冊了提供程序?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM