Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么验证不工作?_Javascript_Angularjs_Validation - Fatal编程技术网

Javascript 为什么验证不工作?

Javascript 为什么验证不工作?,javascript,angularjs,validation,Javascript,Angularjs,Validation,我有以下HTML输入: <input type="text" name="artist" maxlength="45" ng-class="{'error': $scope.formAddSong.artist.$invalid && !$scope.formAddSong.artist.$pristine && $scope.formAddSong.artist.$setUntouched}" class="form-control" placehold

我有以下HTML输入:

 <input type="text" name="artist" maxlength="45"
ng-class="{'error': $scope.formAddSong.artist.$invalid && !$scope.formAddSong.artist.$pristine && $scope.formAddSong.artist.$setUntouched}"
class="form-control" placeholder="Artist"
ng-minlength="minlength"
ng-model="formSong.artist[$index]"
required autofocus>
和名为name=formAddSong的表单

因此,当我触摸输入并将其保留为空时,我不会在该元素上出现类错误。

试试这个:

<input type="text" name="artist" maxlength="45"
                           ng-class="{'error': $scope.formAddSong.artist.$touched && $scope.formAddSong.artist.$error}"
                           class="form-control" placeholder="Artist"
                           ng-minlength="minlength"
                           ng-model="formSong.artist[$index]"
                           required autofocus />

将$setUntouched更改为$untouched删除$setUntouched更改为$untouched,验证有效,但afetr提交表单和清除表单所有字段都有错误classJust debug。。在输入后添加{{$scope.formAddSong.artist.$invalid}}以检查值。当我提交表单后,所有字段均为空,并出现类错误