I'm trying to develop a login with cookies check if a user is already logged or not.
In order, I include the app:
angular.module('ELOAuthentication', [
'AuthenticationService',
'ngRoute',
'ngCookies',
'angular-loading-bar'
])
Then the service
angular.module('ELOAuthentication').factory('AuthenticationService', function ($rootScope, $scope, $http) {
var service = {};
service.Login = function (email, password, callback) {
var Url = '/api/user/GetLoginByEmailPassword';
$http.then(Url, { email: email, password: password }).success(
function (response) {
var data = response.data
callback(data);
}).catch(function (error) {
console.log('ERROR GetLoginByEmailPassword: ' + error);
});
}
service.SetCookie = function (email, password) {
};
service.ClearCookie = function () {
};
});
Finally the AngularJS controller.
angular.module('ELOAuthentication').controller('LoginController', function ($rootScope, $scope, $http) {
AuthenticationService.ClearCookie();
$scope.init = function () {
}
$scope.login = function () {
};
});
I receive the error:
Uncaught Error: [$injector:modulerr]
. What is wrong?
angular.module('ELOAuthentication', [ 'ngRoute', 'ngCookies', 'angular-loading-bar' ])no need to includeAuthenticationServicein herereturn serviceat the end of factory.angular.module('ELOAuthentication').controller('LoginController', function ($rootScope, $scope, $http,AuthenticationService) { AuthenticationServiceyou should add this$http.then(...)be$http.post(...)instead?