我正在执行如下动态表单验证:
<form role="form" name="myForm">
<div class="row" ng-repeat="field in fields">
<div class="form-group">
<input type="text" class="form-control" placeholder="{{field.title}}" name="formData[field.name]" ng-model="formData[field.name]" required ng-minlength=5 ng-maxlength=20>
<div class="error">
<small class="error" ng-show="myForm.formData[field.name].$error.minlength">
{{field.minValidationMessage}}
</small>
</div>
</div>
</div>
...
</form>
我的控制器如下:
$scope.fields = [{
name: 'name',
title: 'Name',
placeholder: 'Enter product name',
...
},{
name: 'code',
title: 'Code',
placeholder: 'Enter product code',
...
}]
$scope.formData = {
name: '',
code: ''
};
以下代码不起作用:
<small class="error" ng-show="myForm.formData[field.name].$error.minlength">
{{field.minValidationMessage}}
</small>
但是,如果没有 ng-repeat(static),它的工作方式如下:
<small class="error" ng-show="myForm.code.$error.minlength">
Your name is required to be at least 3 characters
</small>
如何myForm.formData[field.name]
在ng-show
.
提前致谢。