【发布时间】:2018-10-01 22:19:05
【问题描述】:
我使用 Angular 6 和 Firebase。我想显示所有约会的列表。以下是我的操作方式。
service.ts
getRDV() {
this.rdvList = this.firebase.list('/rdv');
return this.rdvList;
}
型号:
export class RDV {
key: string;
date: string;
heure: string;
spe: string;
uidpat: string;
uid: string;
status: string;
}
在 ts 中:
export class ListComponent implements OnInit {
rdvList: RDV[];
constructor(
private usersService: UsersService,
private router: Router
) {}
ngOnInit() {
var x = this.usersService.getRDV();
x.snapshotChanges().subscribe(item => {
this.rdvList = [];
item.forEach(element => {
var y = element.payload.toJSON();
y["$key"] = element.key;
this.rdvList.push(y as RDV);
})
console.log(this.rdvList)
})
}
}
在 HTML 中:
<tr *ngFor="let rdv of rdvList| myfilter:term, let i = index">
<div *ngFor="let item of rdvList.rdv.key">
<td> {{item.$key}} </td>
<td> {{item.uidpat}} </td>
<td> {{item.date}} </td>
<td> {{item.heure}} </td>
<td> {{item.spe}} </td>
<td> {{item.uid}} </td>
<td>
<button class="btn btn-primary" (click)="onViewUser(user?.uid)">
Choisir
</button>
</td>
</div>
</tr>
实在是解决不了问题应该改怎么给他们推送到表里还是用模板*ngfor调整问题。
【问题讨论】:
-
请在此处粘贴您的 json
-
ngOnit 中的 snapshotchanges(_) 是什么,为什么不直接从 x 订阅 result。例如。 this.getBenef() 从服务返回一个值,就像 getRDV() this.getBenef().subscribe( res => { this.benefaccountList = res['list']; ...... .....
-
请在此处发布您的 json 响应
-
这个错误是有道理的。你期待一份约会清单。但是您从
/rdv获取。这将在顶层有日期,并且在每个日期内,都会有约会对象。我个人觉得,由于每个约会对象中已经有一个日期字段,因此您不需要将每个约会添加到层次结构中。稍后您可以使用日期本身对其进行过滤。
标签: angular typescript firebase firebase-realtime-database