Hello, maybe some1 will be able to help me.
I want somehow connect, my database with this script, so I could get usernames from database, and stop writing over and over names to this list ----> var usernames = ['Jim', 'John', 'Jill', 'Jackie'];
(function(angular) {
'use strict';
var app = angular.module('form-example1', []);
app.directive('username', function($q, $timeout) {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
var usernames = ['Jim', 'John', 'Jill', 'Jackie']; <--- So maybe there is a way to get usernames from my database, than writing names in this line.
ctrl.$asyncValidators.username = function(modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
// consider empty model valid
return $q.when();
}
var def = $q.defer();
$timeout(function() {
// Mock a delayed response
if (usernames.indexOf(modelValue) === -1) {
// The username is available
def.resolve();
} else {
def.reject();
}
}, 2000);
return def.promise;
};
}
};
});
})(window.angular);