In my angular application, I have a page where I am showcasing an object that contains an array of comments within it. This object is loaded into my class as an Observable and then displayed in the HTML using:
<div class="container-fluid mt--7" *ngIf="drill | async as item else loading">
This allows for a display placeholder until the Observable data loads.
On this page, there is functionality to add a new comment to the existing Drill object. While saving this object to the database works fine, I want to update the existing Drill object with the newly added comment without having to re-query the database to reflect the change.
However, I'm struggling to find a way to update the Observable from inside the .subscribe method of the service call after saving the new comment.
addComments(): void {
const comment = new Comment(null, this.commentsForm.get('comment').value, this.commentsForm.get('rating').value);
this.drillService.addComments(this.id, comment).subscribe(comment => {
---- This is where I'm stuck on what to do ------
});
}