我想用AngularFire2实现重置密码/忘记密码功能.似乎AngularFire2尚未提供函数sendPasswordResetEmail,或者不更新输入.由于sendPasswordResetEmail是AngularFireAuth的一部分,我以为我仍然可以像这样访问这个函数:
(this.af.auth as any).sendPasswordResetEmail('email'). then((result: any) => { console.log('Result:',result); }).catch((err: any) => { console.log('Err:',err); });@H_403_12@打字稿给了我这个错误:
error TS2349: Cannot invoke an expression whose type lacks a call signature.@H_403_12@由于我是typescript angular2的新手,有什么提示我如何访问sendPasswordResetEmail?我的猜测是我必须访问firebase提供的纯js sdk,但我不知道如何.
谢谢.
解决方法@H_403_25@
您可以通过在组件构造函数中注入FirebaseApp来使用现有但未完全实现的AngularFire2 SDK功能,如下所示.这将使您可以访问sendPasswordResetEmail方法:
import { Component,Inject } from '@angular/core';
import { AngularFire,FirebaseApp } from 'angularfire2';
@Component({
selector: 'app-forgot-password',template: '...'
})
export class ForgotPasswordComponent {
private auth: any;
constructor(private af : AngularFire,@Inject(FirebaseApp) fa : any) {
this.auth = fa.auth();
}
onSubmit() {
this.auth.sendPasswordResetEmail(this.user.email)
.then( resp => console.log('sent!') )
.catch( error => console.log('Failed to send',error) );
}
}@H_403_12@
请注意,您现在必须声明您的FirebaseApp实例.
import { Component,Inject } from '@angular/core'; import { AngularFire,FirebaseApp } from 'angularfire2'; @Component({ selector: 'app-forgot-password',template: '...' }) export class ForgotPasswordComponent { private auth: any; constructor(private af : AngularFire,@Inject(FirebaseApp) fa : any) { this.auth = fa.auth(); } onSubmit() { this.auth.sendPasswordResetEmail(this.user.email) .then( resp => console.log('sent!') ) .catch( error => console.log('Failed to send',error) ); } }@H_403_12@请注意,您现在必须声明您的FirebaseApp实例.