Merge pull request #4594 from billccn/master

Made the signature of INgModelController.$validators more precise
This commit is contained in:
Masahiro Wakame
2015-06-14 19:21:10 +09:00
2 changed files with 29 additions and 3 deletions
Regular → Executable
+27 -1
View File
@@ -702,4 +702,30 @@ module locationTests {
$location.path() == '/foo/bar'
$location.url() == '/foo/bar?x=y'
$location.absUrl() == 'http://example.com/#!/foo/bar?x=y'
}
}
// NgModelController
function NgModelControllerTyping() {
var ngModel: angular.INgModelController;
var $http: angular.IHttpService;
var $q: angular.IQService;
// See https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$validators
ngModel.$validators['validCharacters'] = function(modelValue, viewValue) {
var value = modelValue || viewValue;
return /[0-9]+/.test(value) &&
/[a-z]+/.test(value) &&
/[A-Z]+/.test(value) &&
/\W+/.test(value);
};
ngModel.$asyncValidators['uniqueUsername'] = function(modelValue, viewValue) {
var value = modelValue || viewValue;
return $http.get('/api/users/' + value).
then(function resolved() {
return $q.reject('exists');
}, function rejected() {
return true;
});
};
}
+2 -2
View File
@@ -524,11 +524,11 @@ declare module angular {
}
interface IModelValidators {
[index: string]: (...args: any[]) => boolean;
[index: string]: (modelValue: any, viewValue: string) => boolean;
}
interface IAsyncModelValidators {
[index: string]: (...args: any[]) => IPromise<boolean>;
[index: string]: (modelValue: any, viewValue: string) => IPromise<any>;
}
interface IModelParser {