I have a forum application in development where users can ask questions and receive answers, each answer having its own 'like' feature. I am trying to access the 'likes' subcollection when viewing an answer, but I am unsure of how to do so. After researching, I came across collection group queries in Firebase, but my knowledge is limited in this area. Can someone assist me in retrieving the 'likes' collection?
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;
}
Here I am retrieving the comment collection.
<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>
This is the HTML code for displaying comments. I want to include the like count for each comment within this section. How can I retrieve the like collection? https://i.sstatic.net/wF24E.jpg