ng-selected必需的验证不适用于复选框

时间:2019-04-29 10:11:06

标签: angularjs-directive

<label>Mark All Present:</label>
<input type="checkbox" name="checkall" ng-model="checkall">
<select name="status{{$index}}" ng-model="attendance_data[$index].status" required>
    <option value="">Select Status</option>
    <option value="Present" data-ng-selected="checkall">Present</option>
    <option value="Late">Late</option>
    <option value="Absent">Absent</option>
</select>
<span ng-show="submitted && attendance_form.status{{$index}}.$error.required">is Required</span>

点击选中的复选框值, 但在提交时显示为必填。 如果我用鼠标一按就选择了它的值。

1 个答案:

答案 0 :(得分:0)

快速查看ngSelected文档:Note: ngSelected does not interact with the select and ngModel directives, it only sets the selected attribute on the element. If you are using ngModel on the select, you should not use ngSelected on the options, as ngModel will set the select value and selected options.

您应该更新复选框,以在ngChange上适当设置选择模型值。