我有一个验证无线电输入的表格。无线电输入是必需的(用户必须在单击提交按钮之前选择其中一个无线电字段)。我正在使用输入广播中需要的ng。
收音机输入看起来像这样:
<input type="radio" name="myRadio" value="1" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="2" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="3" ng-model="theModel" ng-required="!theModel">
我想在用户提交后在我的表单中显示一条消息。我使用了ng-message指令。我这样用它:
<div class="msg-error-input" ng-if="!theModel" ng-messages="myForm.myRadio" role="alert">
<div class="icon my-icon" ng-message="required">
It has to show an error here. But this doesn't seem to work ! It seems that there's no link between the ng-message='required' and the ng-required..
</div>
</div>
答案 0 :(得分:1)
我通过这样做解决了这个问题:
<form name="myForm" id="myForm">
<input type="radio" name="myRadio" value="1" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="2" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="3" ng-model="theModel" ng-required="!theModel">
<div class="msg-error-input" ng-if="!theModel && submitted" ng-messages="myForm.myRadio" role="alert">
<div class="icon my-icon" ng-message="required">
It has to show an error here. But this doesn't seem to work ! It seems that there's no link between the ng-message='required' and the ng-required..
</div>
</div>
<button type="submit" data-ng-click="submitted"/>
</form>
(我看到ng-submitted没有添加到我的表单中,所以我添加了一个点击提交的变量)