1
我想在用户单击提交表单后显示验证消息。 例如文本框是必需的,用户直接点击提交按钮,然后应显示验证字段。在提交Angularjs表单时显示验证消息
这里当用户点击表单时什么都不会发生。
<body ng-controller="AppController as ctrl">
<form ng-submit="ctrl.submit()" name="myForm" novalidate>
<input type="text" ng-model="ctrl.user.username" name="uname" class="username" placeholder="Enter your name" required ng-minlength="3" />
<span ng-show="myForm.$dirty && myForm.uname.$error.required">This is a required field</span>
<input type="text" ng-model="ctrl.user.address" placeholder="Enter your Address" /><br /><br />
<input type="email" ng-model="ctrl.user.email" name="email" class="email" placeholder="Enter your Email" required />
<span ng-show="myForm.$dirty && myForm.email.$error.required">This is a required field</span>
<input type="submit" value="Submit">
</form>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js">
</script>
<script>
angular.module('myApp', [])
.controller('AppController', [function() {
var self = this;
self.submit = function() {
console.log('Form is submitted with following user', self.user);
};
}]);
</script>
谢谢,我正在学习角1你可以建议一些有用的链接。 – Dave