检查一个输入框为空 [英] Check if a input box is empty

查看:140
本文介绍了检查一个输入框为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查是否给定的输入控件是空的?我知道有 $质朴告诉在球场上的属性,如果某一领域最初是空的,但如果什么时候有人填写字段并再次猛拉的全部内容?

How can I check if a given input control is empty? I know there is $pristine property on the field which tells that if a given field is empty initially but what if when someone fill the field and yanks the whole content again?

我觉得上面的功能是必要的,因为它告诉,要求外地用户非常重要的。

I think above feature is necessary as its important for telling the user that field is required.

任何想法将AP preciated!

Any idea will be appreciated!

推荐答案

很简单

<input ng-model="somefield">
<span ng-show="!somefield.length">Please enter something!</span>
<span ng-show="somefield.length">Good boy!</span>

您也可以使用 NG-隐藏=somefield.length而不是 NG-秀=!somefield.length如果你读自然更多。

You could also use ng-hide="somefield.length" instead of ng-show="!somefield.length" if that reads more naturally for you.

有一个更好的选择可能是真正地角的形式的能力优势:

A better alternative might be to really take advantage of the form abilities of Angular:

<form name="myform">
  <input name="myfield" ng-model="somefield" ng-minlength="5" required>
  <span ng-show="myform.myfield.$error.required">Please enter something!</span>
  <span ng-show="!myform.myfield.$error.required">Good boy!</span>
</form> 

这里更新Plnkr。

这篇关于检查一个输入框为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆