我的代码如下所示:
<ng-form name="form">
<div>
Question 1
<label>
<input type="radio" ng-model="q1" style="visibility: initial; position: relative;"
ng-value="false">
No
</label>
<label>
<input type="radio" ng-model="q1" style="visibility: initial; position: relative;"
ng-value="true" ng-required="!(q1||q2||q3)">
Yes
</label>
</div>
<div ng-show="!q1">
Question 2
<br/>
<label>
<input type="radio" ng-model="q2" style="visibility: initial; position: relative;"
ng-value="false">
No </label>
<br/>
<label>
<input type="radio" ng-model="q2" style="visibility: initial; position: relative;"
ng-value="true" ng-required="!(q1|| q2|| q3)">
Yes </label>
<br/>
</div>
<div ng-show="!q1 && !q2">
Question 3
<br/>
<label>
<input type="radio" ng-model="q3" style="visibility: initial; position: relative;"
ng-value="false">
No
</label>
<br/>
<label>
<input type="radio" ng-model="q3" style="visibility: initial; position: relative;"
ng-value="true" ng-required="!(q1|| q2|| q3)">
Yes
</label>
<br/>
</div>
</ng-form>
所以,我需要一个(而且只有一个)“是”的问题答案。然而,$form.invalid 总是假的。我看到 'required="required"' 在应该添加时已成功添加到输入字段,因此 ng-required 条件可以正常工作;)。