【发布时间】:2021-09-07 16:04:21
【问题描述】:
我正在尝试通过其 ID 和该贷款中项目的详细信息来获取特定贷款的信息,以将其显示在详细信息页面中。但是,我无法也不知道如何使用提供给我的贷款服务的 getLoanById 方法检索贷款和贷款项目。
detail.page.ts
export class DetailPage {
loan: Loan;
loanId: string;
constructor(private route: ActivatedRoute, private loanService: LoanService) {
this.loanId = this.route.snapshot.params.id;
this.loan = this.loanService.getLoanById(this.loanId);
}
}
loan.service.ts
getLoanById(id: string) {
return firebase.firestore().collection('loans').doc(id).get().then(doc => {
let loan = new Loan(doc.data().username, doc.data().status, doc.data().duedate.toDate(), doc.id);
return firebase.firestore().collection('loans/' + id + '/items').get().then(collection => {
loan.items = []; // Empty array
collection.forEach(doc => {
let item = new Item(doc.id, doc.data().quantity);
loan.items.push(item);
})
return loan;
});
});
}
【问题讨论】:
标签: angular firebase ionic-framework google-cloud-firestore