【发布时间】:2017-05-03 18:21:59
【问题描述】:
我正在关注本教程:https://javebratt.com/angularfire2-email-auth/,但出现了一个奇怪的错误。
我在登录页面实现,这两个文件我已经实现了
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 的奇怪错误
“AuthData”类型上不存在属性“loginUser”
这个 loginUser 函数在我的 auth-data.ts 中,所以我不明白它是什么意思。
我的猜测是“this.authData”从未启动,但即使我在构造函数中添加this.authData = authData,它也不会改变任何东西。 (这也说明我不明白它是如何启动的)
有人知道我为什么会收到此 loginUser 错误吗?
非常感谢
编辑:
感谢您在下面的一条建议,错误似乎已经消失,并且出现了一个新错误(即使现在说实话,即使我恢复更改,我仍然会收到新错误,我很困惑)
现在我在 Safari 中遇到的错误是 TypeError: undefined is not an object (evalating 'type.parameters') 而在 Firefox 中:TypeError: type is undefined[En savoir plus]
Firefox 控制台给了我
ReflectionCapabilitieshttp://localhost:8100/build/main.js:45824:1 反射器http://localhost:8100/build/main.js:45964:16 编译元数据解析器http://localhost:8100/build/main.js:25506:38 编译元数据解析器http://localhost:8100/build/main.js:25471:21 CompileMetadataResolverhttp://localhost:8100/build/main.js:25357:51 地图自托管 编译元数据解析器http://localhost:8100/build/main.js:25356:65 RuntimeCompiler http://localhost:8100/build/main.js:40363:24 RuntimeCompilercompileModuleAndComponents http://localhost:8100/build/main.js:40301:32 RuntimeCompiler http://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
我很困惑,一定是错误地启动了一些东西,但错误堆栈并没有真正帮助......
【问题讨论】:
-
您能否使用文件夹结构扩展您的示例,以便我们验证您正在导入正确的 auth-data.ts 文件?
标签: angular typescript firebase ionic2 angularfire