不确定如何解决这个问题。我希望有一个基于复选框表单的字符串数组。我将所有值设置为添加到同一个数组(MenteeLevelPrefernce),但是当我选中一个框时,它们都会被检查。我在这里做错了什么?
<label for="mentorPrefCheck">Mentee Level Preference (select all that apply)</label>
<div class="form-group" id="mentorPrefCheck">
<label class="checkbox-inline">
<input type="checkbox" id="hsLevelCheck" [(ngModel)]="mentor.MenteeLevelPreference" name="menteeLevelPreference" value="Highscool"> Highschool</label>
<label class="checkbox-inline">
<input type="checkbox" id="undergradLevelCheck" [(ngModel)]="mentor.MenteeLevelPreference" name="menteeLevelPreference" value="Undergraduate"> Undergraduate</label>
<label class="checkbox-inline">
<input type="checkbox" id="gradLevelCheck" [(ngModel)]="mentor.MenteeLevelPreference" name="menteeLevelPreference" value="Graduate"> Graduate</label>
</div>
答案 0 :(得分:0)
为[(ngModel)]和名称属性
使用唯一变量<div class="form-group" id="mentorPrefCheck">
<label class="checkbox-inline">
<input type="checkbox" id="hsLevelCheck" [(ngModel)]="mentor.MenteeLevelPreference1" name="menteeLevelPreference1" value="Highscool"> Highschool</label>
<label class="checkbox-inline">
<input type="checkbox" id="undergradLevelCheck" [(ngModel)]="mentor.MenteeLevelPreference2" name="menteeLevelPreference2" value="Undergraduate"> Undergraduate</label>
<label class="checkbox-inline">
<input type="checkbox" id="gradLevelCheck" [(ngModel)]="mentor.MenteeLevelPreference3" name="menteeLevelPreference3" value="Graduate"> Graduate</label>
</div>