From 284b8e03ffb49cce62c24b117ced85bbbb72ebeb Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Sat, 14 Feb 2015 22:35:16 -0500 Subject: [PATCH] Properly observe angular dependency injection in main --- public/js/main.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 039df37d42..2038a91d75 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -167,7 +167,7 @@ profileValidation.controller('doneWithFirst100HoursFormController', ['$scope', } ]); -profileValidation.directive('uniqueUsername', function($http) { +profileValidation.directive('uniqueUsername',['$scope', '$http',function($http) { return { restrict: 'A', require: 'ngModel', @@ -186,22 +186,25 @@ profileValidation.directive('uniqueUsername', function($http) { }); } } -}); +}]); -profileValidation.directive('existingUsername', function($http) { +profileValidation.directive('existingUsername', ['$http', function($http) { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attrs, ngModel) { element.bind("keyup", function (event) { - if (element.val().length > 0) { + console.log(element.val()); + if ($('#completed-with').val().length > 0) { ngModel.$setValidity('exists', false); } else { $('#completed-with').removeClass('ng-dirty'); ngModel.$setPristine(); } - if (element.val()) { - $http.get("/api/checkExistingUsername/" + element.val()).success(function (data) { + if ($('#completed-with').val()) { + $http + .get("/api/checkExistingUsername/" + $('#completed-with').val()) + .success(function (data) { console.log('Data received from api call is: ', data); ngModel.$setValidity('exists', data); }); @@ -209,13 +212,13 @@ profileValidation.directive('existingUsername', function($http) { }); } } -}); +}]); -profileValidation.directive('uniqueEmail', function($http) { +profileValidation.directive('uniqueEmail', ['$http', function($http) { return { restrict: 'A', require: 'ngModel', - link: function (scope, element, attrs, ngModel) { + link: function getUnique (scope, element, attrs, ngModel) { element.bind("keyup", function (event) { ngModel.$setValidity('unique', true); if (element.val()) { @@ -230,4 +233,4 @@ profileValidation.directive('uniqueEmail', function($http) { }); } } -}); \ No newline at end of file +}]); \ No newline at end of file