【发布时间】:2021-06-01 03:21:45
【问题描述】:
我想在集合'action'中获取数据
ticket
->document in ticket collection(id)
->**action**
->document in action collection(id)
-> data
我有 .ts 和服务,但我不知道如何在 .html 中显示数据
app.html
<div class="row" *ngFor="let action of Action">
*<!-- {{ action.payload.doc }} -->
<!-- {{ getAction(action) }} -->*
</div>
app.ts
ngOnInit() {
this.auth.user$.subscribe(user => this.user = user)
this.ticket$ = this.ticketService.getTicketByid(this.id);
this.action = this.ticketService.getTrack(this.id).snapshotChanges().subscribe(data => {
data.map(items => {
const item = items.payload.doc.data();
const id = items.payload.doc.id;
return { id, ...item };
})
})
}
应用程序服务
getTrack(id: string): any {
return this.afs.collection('ticket').doc(id)
.collection('action', ref => ref
.orderBy('date', 'desc'))
}
【问题讨论】:
-
至少在
*ngFor="let action of Action">和this.action = this.ticketService.getTrack(this.id).snapshotChanges()...之间的大小写不匹配。我建议将集合命名为复数,所以this.actions = this.ticketService.getTrack(this.id).snapshotChanges()和*ngFor="let action of actions">
标签: javascript angular firebase google-cloud-firestore angularfire2