<form name="LPform">
<div class="form-row clearfix">
<label class="lbl-fld" style="margin-left: 12%;">Email ID</label>
<input class="mob-adj-inpbx" type="email" name="uemail" ng-model="useremail" placeholder=" me@example.com" ng-required="true"/>
<div ng-show="LPform.uemail.$valid">Enter a valid email.</div>
</div>
</form>
在这里,我正在为“电子邮件”添加验证,并且仅在用户输入无效电子邮件时尝试显示错误消息。但这不起作用。
答案 0 :(得分:1)
如果输入无效,我想你想显示错误信息
ng-show="!LPform.uemail.$valid"
也许您忘了将它绑定到范围变量?因为它似乎工作正常。
function Ctrl($scope) {
$scope.useremail = '';
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<div ng-app>
<div ng-controller="Ctrl">
<form name="LPform">
<div class="form-row clearfix">
<label class="lbl-fld">Email ID</label>
<input class="mob-adj-inpbx" type="email" name="uemail" ng-model="useremail" placeholder=" me@example.com" ng-required="true" />
<div style="font-size: 11px; color: red; margin: 5px 65px;"
ng-show="!LPform.uemail.$valid">Please enter a valid email.</div>
</div>
</form>
</div>
</div>
&#13;