Hi, You need a webservice (implementation is up to you) which connects to the database and gives you the desired result in JSON format.
On 21 September 2015 at 14:33, deividasdevd <[email protected]> wrote: > 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); > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- -- Csanyi Andras (Sayusi Ando) -- http://sayusi.hu -- http://facebook.com/andras.csanyi -- ""Trust in God and keep your gunpowder dry!" - Cromwell -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
