<div > <!--<button ng-click="onSubmit()">Register</button>--> <button ladda = "submitting" data-style="expand-right" type="submit"> <span ng-show="submitting">正在注册...</span> <span ng-show="!submitting">注册</span> </button> </div>
● ladda属性值为bool值,true表示显示动态等待效果,false不显示动态等待效果,这里的submitting是scope中的一个属性
● data-style="expand-right"表示在按钮的右侧显示动态等待效果
再拿表单中的Age字段来说:
<div > <label for="age">Age</label> <input type="number" ng-model="formModel.age" required="required" min="18" max="65" ng-min-err-type="tooYoung" ng-max-err-type="tooOld" /> </div>
其中,min, max为AgularJS的directive,而ng-min-err-type是angular-auto-validate的directive。这里遵循的惯例是ng-AngularJS表单验证的directive名称-err-type,而tooYoung和tooOld的作用是什么,又是在哪里用上了呢?
是在module层面用上了,定义在了form_validation_auto.js文件中。
var myApp1 = angular.module('myApp1',['jcs-autoValidate','localize','angular-ladda']); myApp1.run(function(defaultErrorMessageResolver){ defaultErrorMessageResolver.getErrorMessages().then(function(errorMessages){ errorMessages['tooYoung'] = '年龄必须小于{0}'; errorMessages['tooOld'] = '年龄不能大于{0}'; errorMessages['badUsername'] = '用户名只能包含数字、字母或下划线'; }); }); myApp1.controller('myCtrl1', function($scope, $http){ $scope.formModel = {}; $scope.submitting = false; $scope.onSubmit = function(){ $scope.submitting = true; console.log('已提交'); console.log($scope.formModel); $http.post('url',$scope.formModel) .success(function(data){ console.log(':)'); $scope.submitting = false; }) .error(function(data){ console.log(':('); $scope.submitting = false; }); }; });
以上,在run方法中使用angular-auto-validate的defaultErrorMessageResolver服务,对错误信息进行为了自定义。页面上的tooYoung和tooOld和这里的errorMessages['tooYoung']和errorMessages['badUsername']对应。