将 ng-message 与 ng-requuried 一起使用
Use ng-message with ng-requried
我有一个验证无线电输入的表单。无线电输入是必需的(用户必须在单击提交按钮之前选择其中一个无线电字段)。我正在输入无线电中使用所需的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 消息指令。我这样使用它:
<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>
我通过执行以下操作解决了这个问题:
<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提交的没有添加到我的表单中,所以我在点击时添加了一个提交的变量)
相关文章:
- 与ng一起使用localstorage Change dons'不起作用
- 将 ng-message 与 ng-requuried 一起使用
- 如何将 ng-repeat 与图像映射区域标签一起使用
- ng-select 选项在与自定义指令一起使用时加倍
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- 可以将ng模式与变量一起使用吗
- 如何将javascript变量与ng重复过滤器一起使用
- 使ng-show/ng-hide与由Angular之外的外部源修改的localStorage一起工作
- 如何将javascript文件与ng-include模板一起加载
- 如何将 ng-click 与多个表达式一起使用
- 如何将 ng-show 与控制器中返回 true/false 的函数一起使用
- ui-router 如何与 ng-animate 一起工作
- ng-如果不与ng-src一起工作
- javascript [],[[]] 和 [{}] 在 angularJS 中与 ng-repeat 一起使用时的工作差
- 两个 ng 单击函数不会一起执行
- 将 Json 文件存储在 AngularJS 变量中,以便与“ng-repeat”一起使用
- 将 ng 选项与嵌套数组一起使用
- 将 ng-style 与 switch 语句一起使用 - angular JS
- 角度ng重复传递项以与父数据一起使用
- 如何使“ng-”与任何属性一起使用