离子/角度,从字段数组提交输入字段



我对应该如何去做有点困惑。我的应用程序中有一个"提要",提要中的每个帖子都有一个评论框。下面是一些示例代码:

<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>

现在我正在努力弄清楚的是feedPostComment()从上面的输入字段中提取文本的最佳方法。我知道我可以使用ngModel,而且在许多情况下,我在页面上使用表单和输入系统,它们不会以这种方式重复,但我只是无法理解在这种情况下我将如何做到这一点。

我在想我可以将post.id设置为ion-input上的idname字段,并直接通过 DOM 定位输入字段,但我意识到这不是好的做法。

另一件事是,提要本身将定期更新新帖子。提前衷心感谢。

ngModel与对象属性一起使用,以存储添加到该特定帖子的评论。 这是一个堆栈闪电战示例。

<ion-card class="feed" *ngFor="let post of feed">
<ion-item no-lines class="comment-input">
<ion-input [(ngModel)]="post.comment" type="text" placeholder="Write comment ..."></ion-input>
<button item-right ion-button (click)="feedPostComment(post)">Comment</button>
</ion-item>
</ion-card>

//controller 
feedPostComment(post) {
console.log('post_comment => ', post.comment);
console.log('post_id => ',post.id);
}

最新更新