【发布时间】:2019-08-13 17:26:45
【问题描述】:
我正在使用 FireStore,我只需要将集合列表数据显示到组件上,并且在显示的每个项目旁边都可以删除该项目。
我需要使用 SnapShotChanges() 来获取我的删除方法的 ID。
这是我的代码。没有控制台被控制台记录。我正在使用 Angular 7。
userCollection: AngularFirestoreCollection<any>;
collection: any;
constructor(private afs: AngularFirestore, private adminService: AdminServiceService) { }
ngOnInit() {
this.userCollection = this.afs.collection<any>('valuation');
this.collection = this.userCollection.snapshotChanges().pipe(
map(actions => {
actions.map(a => {
console.log(a.payload.doc.data);
console.log(a.payload.doc.id);
})
}
))
}
这是我的模板:
<tbody *ngFor="let o of collection | async">
<tr>
<td scope="row">
{{o.address}}
</td>
<td scope="row">
{{o.name}}
</td>
<td scope="row">
{{o.email}}
</td>
<td scope="row">
{{o.phone}}
</td>
<td scope="row">
<button mat-button color="warn" class="delete" type="button" (click)="delete(o)">Delete</button>
</td>
</tr>
</tbody>
【问题讨论】:
-
开发者工具 > 网络选项卡上有什么有趣的地方吗?
-
很遗憾没有...
-
您尝试 console.log 的方式有点奇怪,因为它是返回对象的一部分。您可以尝试在地图运算符之前添加一个点击运算符吗?
tap( (actions) => console.log('actions', actions));
标签: angular firebase google-cloud-firestore