Я следую этому руководству: https://javebratt.com/angularfire2-email-auth/ и получаю странную ошибку.Undefined - это не объект (оценка 'type.parameters')
Я в реализации Войти страницы, и я уже реализовали эти два файла
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 });
}
}
Но когда Я делаю «ионную подачу». Я получаю следующую странную ошибку: login.ts
Property 'loginUser' does not exist on type 'AuthData'
Эта функция loginUser находится здесь, в моем auth-data.ts, поэтому я не понимаю, что это значит.
Предполагалось, что «this.authData» никогда не инициируется, но даже когда я добавляю в конструктор this.authData = authData
, это ничего не меняет. (что также говорит, что я не понимаю, как он инициируется)
Кто-нибудь знает, почему я получаю эту ошибку loginUser?
Большое спасибо
EDIT:
Благодаря одной из ваших советов ниже Похоже, что ошибка исчезла, и новый здесь (даже если быть честным теперь, даже если я вернуть мои изменения Я все еще получаю новую ошибку, я так запутался)
Теперь ошибка, которую я получаю в Safari, - TypeError: undefined не является объектом (оценка «type.parameters») и в Firefox: TypeError: type undefined [ 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
Я так растерялся, что-то должно быть неправильно инициирована но стек ошибок не помогает ...
Не могли бы вы расширить свой пример с помощью структуры папок, чтобы убедиться, что вы импортируете правильный файл auth-data.ts? – Fjut