我有以下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"
的表单。
所以,当我触摸输入并将其留空时,我不会在此元素上获得类error
。
答案 0 :(得分:1)
试试这个:
<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 />