我正在 AngularJS 中创建一个表单,我想验证这些字段,问题是只有在输入中写了一些东西并且在我删除它之后才会出现所需的消息,但我希望消息出现在聚焦输入之后
我的代码如下
<input type="text" name="textInput" data-ng-model="field.data" class="form-control" required/>
<span ng-show="form.textInput.$dirty && form.textInput.$error.required">Required!</span>
最佳答案
尝试以下操作
<span ng-show="form.textInput.$touched && form.textInput.$error.required">Required!</span>
这将在您触摸并离开(失去焦点)且字段无效后显示消息。 Documentation
关于javascript - $dirty 设置焦点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33811928/