Quite simple:
原文链接:https://www.f2er.com/angularjs/146172.html<input ng-model="somefield"> <span ng-show="!somefield.length">Please enter something!</span> <span ng-show="somefield.length">Good boy!</span>
你也可以使用ng-hide =“somefield.length”而不是ng-show =“!somefield.length”,如果这更自然地为你读。
一个更好的选择可能是真正利用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>