[英]Can not validate the input field taking name dynamically using Angular.js
I need one help. 我需要一个帮助。 Actually i am getting the following error while trying to validate the input field by taking the field name dynamically using Angular.js. 实际上,在尝试通过使用Angular.js动态获取字段名称来验证输入字段时,出现以下错误。
Error: 错误:
TypeError: Cannot read property '$invalid' of undefined
I am explaining my code below. 我在下面解释我的代码。
<form name="billdata" id="billdata" enctype="multipart/form-data" novalidate>
<div ng-repeat="mul in mulImage">
<input type="file" class="filestyle form-control" data-size="lg" name="upload_{{$index}}" id="bannerimage_{{$index}}" ng-model="mul.image" ngf-pattern="'image/*'" accept="image/*" ngf-max-size="2MB" ngf-select="onFileSelect1($index);">
</div>
<input type="button" class="btn btn-success" ng-click="saveResturantDetails(billdata);" id="saveData" value="Save" style="margin-right:20px;"/> </div>
</form>
Here i am uploading multiple images and when user will click on save
button the it should first validate. 我在这里上传多个图像,当用户单击“ save
按钮时,它应该首先进行验证。 I am explaining my controller side code below. 我在下面解释我的控制器端代码。
$scope.saveResturantDetails=function(billdata){
if(billdata.$valid){
}else{
if(angular.isDefined($scope.mulImage)){
for(var i=0;i<$scope.mulImage.length;i++){
var name='upload_'+i;
if(billdata.name.$invalid){
alert('Please add the valid image(i.e-.png or .jpeg) of size upto 2 mb max in image field'+(i+1));
return false;
}
}
}
}
}
Actually i am getting the error in this if(billdata.name.$invalid)
actually it can not take the proper name.If i am writing like this 'billdata.upload_0.$invalid' its working fine. 实际上我在if(billdata.name.$invalid)
这个错误实际上不能使用正确的名称。如果我像这样写'billdata.upload_0。$ invalid'它的工作正常。 But here i need to attach the name dynamically. 但是在这里我需要动态附加名称。 Please help me. 请帮我。
这项工作会:
billdata[name].$invalid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.