我正在尝试使用Firebase实施电子邮件登录,但是以某种方式将无法正常工作。
在我的AuthService中,我有以下代码:
export class AuthService {
constructor(public afAuth: AngularFireAuth, public router: Router, public ngZone: NgZone) { }
SignIn(email, password) {
console.log('Test');
return this.afAuth.auth.signInWithEmailAndPassword(email, password)
.then((result) => {
this.ngZone.run(() => {
this.router.navigate(['admin']);
});
}).catch((error) => {
window.alert(error.message);
});
}
}
“测试”出现在控制台内部(没有其他内容),因此我认为错误必须在函数SignIn
内。
但是为了完整起见,调用了服务功能的代码:
<button type="submit" class="btn btn-primary" (click) = "login(email.value, password.value)" > Submit</button >
// MARK: - Typescript:
export class LoginComponent implements OnInit {
constructor(public authService: AuthService) { }
login(email: string, password: string): void {
this.authService.SignIn(email, password);
}
ngOnInit() {
}
}
编辑: 尚未找到解决方案,在提交页面时会自动重新加载页面(以防万一,这是有价值的信息)。