我正在使用Angular 5和Firestore,并且我有一项服务,可以通过他的ID或所有学生的身份获取一名学生,但是我想提供一种通过其电子邮件获取一名学生的方法。我提供这项服务的目的是让他的ID成为学生:
getStudient(uid: string){
this.studientDoc = this.afs.doc<StudientsInterface>(`studients/${uid}`);
this.studient = this.studientDoc.snapshotChanges().map(action => {
if (action.payload.exists === false){
return null;
}else{
const data = action.payload.data() as StudientsInterface;
data.uid = action.payload.id;
return data;
}
});
return this.studient;}
另外一个用于呼叫服务:
constructor(private studientService: StudientService){
this.currentStudient = localStorage.getItem('studientEmailLS');
this.studientService.getStudient(this.currentStudient).subscribe(studient => {
this.studientName = studient.name;
}) }
我尝试了这段代码,但是没有用:
getStudientByEmail(email: string){
this.studientDoc = this.afs.doc<StudientsInterface>(`studients/${email}`);
this.studient = this.studientDoc.snapshotChanges().map(action => {
if (action.payload.exists === false){
return null;
}else{
const data = action.payload.data() as StudientsInterface;
data.uid = action.payload.id;
data.email = action.payload.get(email);
return data;
}
});
return this.studient;
}
我可以检索UID,但是在句子“ action.payload。*”中看不到参数“ email”
如何通过电子邮件致电服务并获取所有对象数据?