I have an Angular (v7) project and there is a comment list on a component as shown below. I list comments in an *ngFor loop and add new ones to the list. However I reload the list after adding a new comment and I think there is a better way i.e. appending the newly added comment by combining it with HTML that I have used with JavaScript before. But unfortunately I have not managed to define it (maybe due to the loop). Is it possible in Angular?
#comment-list.html:
<div *ngFor="let comment of comments">
<div class="p-col"> {{ comment.UserName }} </div>
<div class="p-col-12" [innerHTML]="comment.Body"></div>
</div>
I call the method below after adding a new comment:
#comment-list.ts:
listComments() {
this.loading = true;
service.listComments(this)
.subscribe(data => {
this.records = data.Data;
this.loading = false;
});
}
I think I should re-create an HTML list using newly added comment's data and append it to the list but how?
this.comments.push(myNewComment)orthis.records.push(myNewComment)... wala