Angularjs 动态添加字段的验证
我有一个表单,我提供了一个动态添加文件的选项,因为我使用了ng repeat,我的问题是添加的字段表单验证不起作用。这是我的工作代码Angularjs 动态添加字段的验证,angularjs,Angularjs,我有一个表单,我提供了一个动态添加文件的选项,因为我使用了ng repeat,我的问题是添加的字段表单验证不起作用。这是我的工作代码 <fieldset data-ng-repeat="choice in choices" ng-init="count=0"> <div class="form-group"> <label class="col-sm-4 col-md-3">Designation </label>
<fieldset data-ng-repeat="choice in choices" ng-init="count=0">
<div class="form-group">
<label class="col-sm-4 col-md-3">Designation </label>
<div class="col-sm-5 col-md-6">
<input type="text" name="desg_{{$index}}" class="form-control" ng-model="user2.choices[choice.id]" placeholder="Your Job Title" required/>
<span ng-messages="employeeform['desg_' + $index].$error" ng-show="employeeform['desg_' + $index].$touched || employeeform.$submitted">
<span ng-message = "required" class="errorcol">select day</span>
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 col-md-3">Company </label>
<div class="col-sm-5 col-md-6">
<input type="text" class="form-control" name="company_{{$index}}" ng-focus="usercompany_msg=true" ng-model="user2.choices[choice.id_f]" placeholder="where your are currently working"/>
<p ng-show="errorDesg">{{errorDesg}}</p>
</div>
</div>
</fieldset>`
任命
选择日期
单位
{{errorDesg}
`
`-
我的控制器代码是
$scope.addfields = function(){
console.log($scope.choices.length);
if($scope.choices.length<3){
var newItemNo = $scope.choices.length + 1;
var item = {};
item.id = "company" + newItemNo;
item.id_f = "designation" + newItemNo;
item.id_s = "sallac" + newItemNo;
item.id_t = "saltho" + newItemNo;
$scope.choices.push(item);
console.log(JSON.stringify($scope.choices));
}
};
$scope.addfields=function(){
log($scope.choices.length);
if($scope.choices.length这是一个解析器错误。angular指令中的一个表达式错误。请尝试注释部分代码/逐个注释以定位解析错误。为什么要使用ng init=“count=0”Inner ng repeat?您能描述一下错误吗?您的浏览器的调试控制台中有错误吗?您给出的错误可能表明您在ng messages=“employeeform['desg'+$index].$error”
周围有某种语法错误。但我不知道为什么。我觉得它不错。