Properly observe angular dependency injection in main

This commit is contained in:
Nathan Leniz
2015-02-14 22:35:16 -05:00
parent 68ad6f9831
commit 284b8e03ff

View File

@ -167,7 +167,7 @@ profileValidation.controller('doneWithFirst100HoursFormController', ['$scope',
} }
]); ]);
profileValidation.directive('uniqueUsername', function($http) { profileValidation.directive('uniqueUsername',['$scope', '$http',function($http) {
return { return {
restrict: 'A', restrict: 'A',
require: 'ngModel', require: 'ngModel',
@ -186,22 +186,25 @@ profileValidation.directive('uniqueUsername', function($http) {
}); });
} }
} }
}); }]);
profileValidation.directive('existingUsername', function($http) { profileValidation.directive('existingUsername', ['$http', function($http) {
return { return {
restrict: 'A', restrict: 'A',
require: 'ngModel', require: 'ngModel',
link: function (scope, element, attrs, ngModel) { link: function (scope, element, attrs, ngModel) {
element.bind("keyup", function (event) { element.bind("keyup", function (event) {
if (element.val().length > 0) { console.log(element.val());
if ($('#completed-with').val().length > 0) {
ngModel.$setValidity('exists', false); ngModel.$setValidity('exists', false);
} else { } else {
$('#completed-with').removeClass('ng-dirty'); $('#completed-with').removeClass('ng-dirty');
ngModel.$setPristine(); ngModel.$setPristine();
} }
if (element.val()) { if ($('#completed-with').val()) {
$http.get("/api/checkExistingUsername/" + element.val()).success(function (data) { $http
.get("/api/checkExistingUsername/" + $('#completed-with').val())
.success(function (data) {
console.log('Data received from api call is: ', data); console.log('Data received from api call is: ', data);
ngModel.$setValidity('exists', 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 { return {
restrict: 'A', restrict: 'A',
require: 'ngModel', require: 'ngModel',
link: function (scope, element, attrs, ngModel) { link: function getUnique (scope, element, attrs, ngModel) {
element.bind("keyup", function (event) { element.bind("keyup", function (event) {
ngModel.$setValidity('unique', true); ngModel.$setValidity('unique', true);
if (element.val()) { if (element.val()) {
@ -230,4 +233,4 @@ profileValidation.directive('uniqueEmail', function($http) {
}); });
} }
} }
}); }]);