动态添加字段的验证

时间:2016-12-23 14:00:16

标签: angularjs

我有一个表单,我提供了一个动态添加文件的选项,因为我使用ng-repeat,我的promblem用于添加的字段表单验证不起作用。这是我的工作代码。

<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>`

` - 我的控制器代码是

$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));
}
};

我得到的错误是

errorimage

1 个答案:

答案 0 :(得分:0)

这是一个解析器错误。你在一个angular指令里面有错误的表达。尝试评论部分代码/逐个解析解析错误。为什么你有ng-init =&#34; count = 0&#34;在ng-repeat中?

相关问题