我正在尝试使用ng-remote-validate指令进行远程验证。我试图找到一种方法如何在发送到服务器的请求中传递多个值。目前正在使用此
<input type="email" name="email" ng-model="feedBackUser.Email" ng-remote-validate="{ '/Setup/CheckEmailExist' : 'uniqueEmail', '/Setup/SelfUserCheck' : 'selfusercheck'}" placeholder="Email" ng-remote-method="GET" class="form-control " required />
但我需要传递多个参数。我正在使用ng-remote-Validate Directive https://github.com/webadvanced/ng-remote-validate
参考上面的链接,我正在努力弄清楚这段代码片段的工作原理
$scope.currentPasswordSetArgs = function( val, el, attrs, ngModel ) {
return { value: val, otherData: attrs.otherData };
};
任何帮助都将受到高度赞赏
答案 0 :(得分:-1)
您可以在数据绑定中使用现有变量。 例如创建一个数组:
$scope.myArray = ['/Setup/CheckEmailExist' : 'uniqueEmail', '/Setup/SelfUserCheck' : 'selfusercheck'];
然后你可以在你的指令中使用这个数组,如:
ng-remote-validate="myArray"
我希望这有效!
答案 1 :(得分:-1)
也许你可以试试Angularjs的内置asyncValidators。
它会像这样工作:
.directive("emailNotExistingValidation", ["$http", function($http) {
return {
restrict: "A",
require: "ngModel",
link: function(scope,element,attrs, ngModelCtrl) {
var validation = function(modelValue, viewValue) {
var value = modelValue || viewValue;
return $http.post("/setup/emailExists", {
email: value
});
}
ngModelCtrl.$asyncValidators.emaiNotExisting = validation;
}
}
}]);
行动中:Fiddle
答案 2 :(得分:-1)
我曾经使用ng-remote-interceptors来解决它:
<div ng-controller="MyCtrl as formCtrl">
<form>
<input ng-remote-validate="{ '/some/path' : 'uniqueness' }" ng-remote-interceptors="formCtrl.ngRemoteEmailInterceptors" type="email" name="email" ... />"
</form>
</div>
在MyCtrl
:
this.ngRemoteEmailInterceptors = {
request: function(httpOptions) {
var data = httpOptions.method == 'POST' ? httpOptions.data : httpOptions.params;
data.id = user.id; // Add/change parameters
return httpOptions;
}
}