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