我需要使用 ngFor 進行多個輸入,但是當我輸入一個單詞時,它會在所有輸入中重復,我該如何解決這個問題?

我的代碼:
<div class="" *ngFor="let publication of publications">
...
<form #newCommentForm="ngForm" (ngSubmit)="onSubmit(newCommentForm, $event, publication._id)">
<div class="make-comment" >
<img src="{{url 'get-image-user/' publication.user.image }}" *ngIf="publication.user.image" class="rounded-circle-mini align-self-center">
<input type="text" name="#text" #text="ngModel" [(ngModel)]="comment.text" id="input-coment" class="form-control" required placeholder="Your comment">
<button class="btn btn-sm btn-secondary" style="color: #fff;" type="submit"><i class="bi bi-arrow-bar-left"></i></button>
</div>
</form>
</div>
uj5u.com熱心網友回復:
您將變數“comment.text”系結到每個輸入 [模型]。意思是,它的值在所有輸入范圍之間共享。您需要使用“publication”,它僅適用于每個輸入。
*ngFor="let publication of publications"
更改[(ngModel)]="comment.text"為類似的東西[(ngModel)]="publication.text"
uj5u.com熱心網友回復:
您將所有輸入系結到一個屬性comment.text。您應該為每個輸入創建一個屬性并將輸入與其系結。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/379932.html
標籤:javascript 有角的 打字稿 ngfor
