After scouring through countless posts on various forums, I have yet to find a solution to my unique problem. I find myself in a peculiar situation where I am trying to inject a Factory into a Controller, and despite everything appearing to be in order, it just doesn't seem to work as expected.
Below is the factory code snippet:
zimmerApp.factory('AuthService', [function ($http, $sanitize) {
var sanitizeCredentials = function (credentials) {
return {
email: $sanitize(credentials.email),
password: $sanitize(credentials.password),
csrf_token: credentials.csrf_token
};
};
return {
login: function (credentials) {
var login = $http.post("/login", sanitizeCredentials(credentials));
login.success(cacheSession);
login.error(loginError);
return login;
}
};
}]);
And here is the controller where I intend to use AuthService:
zimmerApp.controller('loginCtrl', ['$scope', 'AuthService',
function ($scope, $location, AuthService) {
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "http://" + window.location.hostname + ":8000/auth/token", false);
xhReq.send(null);
$scope.error = false;
$scope.credentials = {
username: '',
password: '',
csrf_token: xhReq.responseText
};
$scope.login = function (credentials) {
AuthService.login($scope.credentials)
.success(function () {
$location.path('/');
})
.error(function (err) {
console.log('error');
});
}
}]);
The error message that keeps popping up reads:
TypeError: Cannot read property 'login' of undefined
It appears that the AuthService factory is not being recognized for some reason. If anyone has any insight on how to resolve this issue, I would greatly appreciate the guidance as I feel like I've tried everything at this point.