I have this following button:
<button mat-button
(click)="toggleLikeQuestion(question['id'])" aria-label="Like this question.">
{{!isQuestionLiked(question) ? 'Like' : 'Unlike'}}
</button>
And this is the action when it's clicked:
public isQuestionLiked = (q): boolean => q['likedBy'].some(s => s['id'] === this.studentId);
toggleLikeQuestion(id: string) {
this.questionService.getQuestion(id).subscribe((question) => {
const isLiked = this.isQuestionLiked(question);
if (question) {
if (!isLiked) {
this.questionService.likeQuestion(id, this.student).subscribe(() => this.questionService.getQuestion(id));
} else {
this.questionService
.unlikeQuestion(id, this.student)
.subscribe(() => this.questionService.getQuestion(id));
}
}
});
}
This works, the only thing is that the button does not update its content (Like or Unlike) after the subscribe function is called after like or un-liking the question. It only updates when I reload the site. What should I do to make it updates without reload the site?
The get question function is http method, so it's an Observable, then it would become nested observable, I'm not sure if that causes the issue. Thank you.