Error: [$injector:unpr] Unknown provider: $localStorageProvider <- $localStorage <- authService
See original GitHub issueHi everyone,
I run project and got something wrong, and I don’t know why
App.js
var app = angular.module(‘AngularAuthApp’, [
‘ngRoute’,
“angularUtils.directives.dirPagination”,
“LocalStorageModule”,
“angular-loading-bar”,
“authService”]);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.otherwise("/");
config.routeHome($routeProvider);
config.routeAccount($routeProvider);
$locationProvider.html5Mode(true);
}]);
Controller (function () { ‘use strict’; angular .module(‘AngularAuthApp’) .controller(‘loginController’, loginController);
loginController.$inject = ['$scope', '$location', 'authService'];
function loginController($scope, $location, authService) {
console.log("loginController");
$scope.login = login;
initController();
function initController() {
// reset login status
authService.Logout();
};
function login() {
$scope.loading = true;
authService.Login($scope.username, $scope.password, function (result) {
console.log(result);
if (result === true) {
$location.path('/home');
} else {
$scope.error = 'Username or password is incorrect';
$scope.loading = false;
}
});
};
}
})(); Service (function () { ‘use strict’;
angular.module('authService', ['angular-loading-bar']).factory('authService', authService);
authService.$inject = ['$http', '$localStorage'];
function authService($http, $localStorage) {
console.log("test");
var service = {};
service.Login = Login;
service.Logout = Logout;
return service;
function Login(userName, password, callback) {
$http.post('/api/token', { username: userName, password: password })
.success(function (response) {
// login successful if there's a token in the response
if (response.token) {
// store username and token in local storage to keep user logged in between page refreshes
$localStorage.currentUser = { username: userName, token: response.token };
// add jwt token to auth header for all requests made by the $http service
$http.defaults.headers.common.Authorization = 'Bearer ' + response.token;
// execute callback with true to indicate successful login
callback(true);
} else {
// execute callback with false to indicate failed login
callback(false);
}
});
}
function Logout() {
// remove user from local storage and clear http auth header
delete $localStorage.currentUser;
$http.defaults.headers.common.Authorization = '';
}
}
})(); Please help me, Thank you so much.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
javascript - Uncaught Error: [$injector:unpr] Unknown provider ...
You're injecting $localStorage but the error message says $localstorage. You're sure about the case? – sp00m. Nov 17, 2015 at 15:16.
Read more >Error: $injector:unpr Unknown Provider - AngularJS: API
This error results from the $injector being unable to resolve a required dependency. To fix this, make sure the dependency is defined and...
Read more >angular interceptor set token in localstorage - You.com
Why does my angular Interceptor take old value of token from localstorage? ... Error: [$injector:unpr] Unknown provider: optionsProvider <- options.
Read more >[$injector:unpr] Unknown provider: auth0Provider <- auth0
Uncaught Error: [$injector:unpr] Unknown provider: auth0Provider <- auth0. 986 views ... 'angular-storage', // for local storage of tokens.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This isn’t our ngStorage. Try adding
👍