[英]ngModel and checkbox/radio not working properly
我為我的應用程序制作了 html 模板。 基本上它是一個帶有文本輸入的單選框/復選框,其中包含問題的答案。 在我決定將 ngModel 添加到它們之前,它工作得很好。 問題是,當我添加 2 個或更多答案並單擊 label 以設置正確的答案(/s)時,只有最后一個選擇,此外,每當我單擊 label 時,答案文本就會消失。
html 文字:
<div *ngIf="question.typeQuestions==1"> <div *ngFor="let item of question.selectedAnswer; let i = index" class="checkbox-variable"> <input type="checkbox" id="customCheckbox{{i}}" name="customCheckbox" class="checkbox-square" [(ngModel)]="item.isCorrect" > <label class="checkbox-label" for="customCheckbox{{i}}"><input class="checkbox-text" type="text" [(ngModel)]="item.text"></label> </div> </div>
ChrisY 解決了這個問題。
具有相同名稱的多個輸入在這里是絕對錯誤的。 試試name="customCheckbox{{i}}"
。 使用 ngModel 時,您需要一個標識表單控件的名稱。 它必須是獨一無二的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.