【发布时间】:2020-11-30 02:44:33
【问题描述】:
我正在开发一个论坛应用程序,用户可以在其中提出问题并获得答案(每个答案都有自己的喜欢) 我想要的是当我访问答案时,我想得到它的子集合。但我不知道如何访问“喜欢”集合。我有 google 并找到了收集组查询的方法,但对 firebase 没有足够的了解。有人能帮我获得“喜欢”吗
getcomments(id) {
this.commentcollection = this.questioncollection.doc(id).collection<Comment>('answer');
this.comments = this.commentcollection
.snapshotChanges()
.pipe(map(changes =>{
return changes.map(a=>{
const data = a.payload.doc.data() as Question;
data.id = a.payload.doc.id;
return data;
})
}));
return this.comments;
}
这里是收集评论,
<li *ngFor="let comment of selectedComment |async">
<div class="comment-main-level">
<div class="comment-box">
<div class="comment-head">
<span>{{comment.time.toDate() | date: 'dd MMM hh:mm'}}</span>
<i>Likes</i>
<i (click)="likepost(comment.userID,comment.id)" class="fa fa-thumbs-up"></i>
<i (click)="editComment($event, comment)" *ngIf="comment.userID==authService.currentUserId" class="fa fa-pencil-alt"> </i>
<i (click)="deleteComment(comment.id)" *ngIf="comment.userID==authService.currentUserId" class="fa fa-trash-alt"></i>
</div>
<div class="comment-content">
{{comment.answerBody}}
</div>
【问题讨论】:
-
喜欢不需要自己的实体/收藏。只需向评论实体添加一个属性(类型 int)...
-
如果用户点击喜欢的数量,我想显示一个喜欢的列表
标签: angular typescript firebase google-cloud-firestore angularfire2