【发布时间】:2018-04-01 18:55:23
【问题描述】:
我有一个包含多个文档的活动集合。我想在单击按钮上检索特定文档。
收藏:活动
文档 ID:自动 ID
字段:activityid、locked、section、maxPlayers、name
我在这里检索整个集合
this.activities = afs.collection('activities', x => x.orderBy('section',
'asc')).valueChanges();
我将这些集合显示为;
<tr *ngFor="let activity of activities | async | paginate: { itemsPerPage: 10, currentPage: p }; let i =index">
<td>
{{activity.section}}
</td>
<td >
{{activity.name}}
</td>
<td>
{{activity.maxPlayers}}
</td>
<td>
{{activity.locked}}
</td>
<td>
<button type="button" class="btn btn-success"
(click)="onEdit(activity.id); secondModal.show() "><i
class="fa fa-pencil"></i>
Edit
</button>
</td>
我在 OnEdit() 函数上传递了一个 id 参数。在 OnEdit 函数中,我想按 id 检索选择性文档。并将模型中的文档字段显示为:
<div *ngFor="let activity of activities | async >
{{activity.section}}
{{activity.name}}
{{activity.maxPlayers}}
{{activity.locked}}
我尝试了很多想法,但没有奏效。它始终显示所有文件。我只想检索通过按钮单击的文档。
【问题讨论】:
-
代码中 onEdit 和 secondModal.show() 函数的内容是什么?
-
在 onEdit() 函数中:this.afs.doc("activities/"+actId).valueChanges();其中 actId 是我在 onClick 方法中传递的文档的 ID。而 secondModal.show() 正在调用一个模式来显示这些文档字段。但是我的模态显示了一个集合的所有文档。
-
查看我的回答,希望对您有所帮助。
标签: angular google-cloud-firestore angularfire2