错误验证在AngularJS中不起作用
Error validation not working in AngularJS
我正在Angular中进行错误验证,如下所示。
<select ng-model = "$parent.color" class = "form-control"
ng-options = "color as color for color in $parent.colors" required>
<option value="">Choose an option</option>
</select>
<span ng-show="serviceForm.$parent.color.$error.required"> My custom error message </span>
错误验证消息永远不会显示。如何解决此问题?
是否包含ngRequire模块?
ng需要
<script>
angular.module('ngRequiredExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.required = true;
}]);
</script>
<div ng-controller="ExampleController">
<form name="form">
<label for="required">Toggle required: </label>
<input type="checkbox" ng-model="required" id="required" />
<br>
<label for="input">This input must be filled if `required` is true:</label>
<input type="text" ng-model="model" id="input" name="input" ng-required="required" /> <br>
<hr>
required error set? = <code>{{form.input.$error.required}}</code><br>
model = <code>{{model}}</code>
如果有效的话,试试这个。
您的代码可以像这样正常工作。
<form name="form1">
<select name="select" ng-model = "$parent.color" class = "form-control"
ng-options = "color as color for color in $parent.colors" required>
<option value="">Choose an option</option>
</select>
<span ng-show="form1.select.$error.required"> My custom error message </span>
</form>
您没有流动FormController。查看此链接
相关文章:
- 我的AngularJS表达式没有'不起作用
- AngularJS指令部分应用的函数don'不起作用
- AngularJS ng include dons'不起作用
- AngularJs和Laravel的Pretty Urls不起作用
- Google Maps API OverlayView()在AngularJS指令中不起作用
- AngularJS ng include won'不知什么原因不起作用
- AngularJS没有'不起作用
- Grunt concat js angularjs 不起作用
- angularjs ng点击运行时标记不起作用
- AngularJS:$on dons'不起作用
- AngularJS-简单的教程不起作用
- 输入类型范围在angularjs重复内不起作用
- 数据绑定在特定情况下不起作用(AngularJS)
- 路由不起作用 AngularJS,只是添加一个哈希
- 在 jsfiddle 中拖放表中的行不起作用 - angularjs
- 提交按钮不起作用 AngularJS
- $location.search() 不起作用 - AngularJs 1.5
- 单击按钮时获取单选按钮值不起作用angularjs
- Ng-repeat不起作用AngularJs
- 提交指令不起作用 AngularJS