Javascript 为什么验证不工作?
我有以下HTML输入: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
<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}}以检查值。当我提交表单后,所有字段均为空,并出现类错误