Jquery 如何验证Angularjs中元素的副本并显示错误消息
我有一个表单,其中多次动态生成相同的元素。提交表单时,我需要验证此表单元素并显示错误消息。 错误消息显示为以下代码,例如:Jquery 如何验证Angularjs中元素的副本并显示错误消息,jquery,angularjs,angularjs-directive,Jquery,Angularjs,Angularjs Directive,我有一个表单,其中多次动态生成相同的元素。提交表单时,我需要验证此表单元素并显示错误消息。 错误消息显示为以下代码,例如: <span class="error input-icon fui-alert" ng-show="historyForm.edutoDate0.$error.beforeDate"></span> edutoDate输入元素是使用ID edutoDate 0、edutoDate 1…动态生成的。。。。 但是没有显示错误消息。删除此索引值0,1
<span class="error input-icon fui-alert" ng-show="historyForm.edutoDate0.$error.beforeDate"></span>
edutoDate输入元素是使用ID edutoDate 0、edutoDate 1…动态生成的。。。。
但是没有显示错误消息。删除此索引值0,1,2。。。它会起作用的。请帮助我找到解决方案。请尝试此代码而不是您的代码
ng-show="historyForm.edutoDate[0].$error.beforeDate">
ng-show="historyForm.edutoDate[1].$error.beforeDate">
ng-show="historyForm.edutoDate[2].$error.beforeDate">
我已经使用了ng form指令并解决了这个问题。我的代码如下所示
<span ng-repeat="experience in userExperience">
<ng-form name="historyExpForm">
<div class="row">
<a ng-click="deleteExperience(experience)" data-action="close" class="delete">
<i class="glyphicon glyphicon-remove"></i>
</a>
<div class="col-xs-6 col-sm-6 col-6">
<label>Position</label>
<input type="text" class="form-control" ng-model="experience.title"/>
</div>
<div class="col-xs-6 col-sm-6 col-6">
<label>Organisation/Company</label>
<input type="text" class="form-control" ng-model="experience.organization"/>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-6">
<label>From date</label>
<input type="text" name="expFromDate" class="form-control" ng-model="experience.fromDate" ui-date />
</div>
<div class="col-xs-6 col-sm-6 col-6">
<label>To date</label>
<div class="form-group has-success">
<input type="text" name="expToDate" class="form-control" ng-model="experience.toDate" ui-date before-date="{{experience.fromDate | date:'dd MMM, y hh:mm a'}}"/>
<span class="error input-icon fui-alert" ng-show="historyExpForm.expToDate.$error.beforeDate"></span>
</div>
</div>
</div>
<hr class="separator"/>
</ng-form>
</span>
位置
组织/公司
从日期开始
迄今为止
beforeDate指令将验证每个子窗体并正确显示错误消息。您能否尝试将此示例放入or中,以便我们可以帮助您进行调试。这可能不起作用有多种原因。我猜是
historyForm.edutoDate0.$error.beforeDate
未找到或引用错误。angular的表单模型从输入元素的name属性而不是ID获取其字段名。请尝试确认edutoDate0
exists。如果它们都具有相同的id或名称,则最有可能是一个数组。