I'm feeling a bit perplexed about how to approach this situation. In my app, there is a "feed" feature where each post includes a comment box. Here's a snippet of the code:
<ion-card class="feed" *ngFor="let post of feed">
<ion-item no-lines class="comment-input">
<ion-input type="text" placeholder="Write comment ..."></ion-input>
<button item-right ion-button (click)="feedPostComment(post)">Comment</button>
</ion-item>
</ion-card>
Now, I'm struggling to determine the best approach for implementing feedPostComment()
to retrieve the text from the input field above it. Although I have used ngModel
in various cases for forms and input fields on non-repeating pages, I am finding it challenging to apply it in this scenario.
One thought I had was to assign post.id
as the id
or name
attribute of the ion-input
, and then access the input field directly via the DOM. However, I am aware that this practice is not recommended.
Additionally, since the feed will be regularly updated with new posts, I appreciate any guidance provided in advance. Thank you.