登录时,输入邮件ID和密码,然后提交。如果邮件ID不在服务中,我如何在angularjs中显示错误消息。
<form name="loginForm">
<div class="container loginPage">
<div class="loginForm">
<div class="formField">
<div class="formBlk">
<label><span>Email</span></label>
<input type="email" class="textBox" name="userEmail" ng-model="userEmail.isLoggedIn" value="" autocomplete="off" required>
</div>
</div>
<div class="formField">
<div class="formBlk">
<label><span>Passcode</span></label>
<input type="password" class="textBox" name="password" ng-model="password" value="" autocomplete="off" required>
</div>
</div>
<input type="submit" class="btn btn-primary" value="Submit" ng-click="loginUser()" ng-disabled="loginForm.userEmail.$pristine || loginForm.userEmail.$invalid || loginForm.userEmail.$error.email && loginForm.password.$pristine || loginForm.password.$invalid || loginForm.password.$error.password">
</div>
</div>
</form>
答案 0 :(得分:0)
您可以使用div在表单中显示错误消息,并将其与ng-show指令绑定,如下所示:
<div id="formErrors" ng-show="emailInvalid"><ul><li class="error">{{message }}</li></ul></div>
如果您想显示字段级别,可以使用以下指令:
<input type="email" class="textBox" name="userEmail" ng-model="userEmail.isLoggedIn" value="" autocomplete="off" ng-class="{ 'hasError': loginForm.userEmail.$invalid }" required>