[英]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.