以下是表单的Html代码。唯一的问题在于,错误消息直到页面加载完成才会显示出来。
有什么建议吗?
编辑
我分享了这个问题的视频链接。
编辑
我分享了这个问题的视频链接。
var app = angular.module('myApp', []);
app.controller('validateCtrl', function($scope) {
});
<form ng-app="myApp" action="#" method="post" ng-controller="validateCtrl" name="myForm" novalidate>
<div class="form-group-custom">
<label>Full Name</label>
<input type="text" name="fullName" class="form-control" placeholder="Full Name" ng-model="fullName" required>
<span style="color:red" ng-show="(myForm.fullName.$dirty && myForm.fullName.$invalid)">
<span ng-show="myForm.fullName.$error.required">Email is required.</span>
</span>
</div>
<div class="form-group-custom">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="useremail" class="form-control" placeholder="Email" ng-model="useremail" required>
<span style="color:red" ng-show="myForm.useremail.$dirty && myForm.useremail.$invalid">
<span ng-show="myForm.useremail.$error.required">Email is required.</span>
<span ng-show="myForm.useremail.$error.email">Invalid email address.</span>
</span>
</div>
<div class="box-footer-custom">
<button class="btn btn-primary" type="submit">Save</button>
<button class="btn btn-danger" type="submit" style="margin-left:10px;">Cancel</button>
</div>
</form>
$touched
属性吗? - JoseMdisplay: none;
到样式中,就像你添加了颜色一样。但正确的方法可能是使用ng-cloak
,只要不要忘记在 HTML 的顶部添加样式:https://code.angularjs.org/1.3.10/docs/api/ng/directive/ngCloak - JoseM