question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: [$injector:unpr] Unknown provider: $localStorageProvider <- $localStorage <- authService

See original GitHub issue

Hi everyone, I run project and got something wrong, and I don’t know why error 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:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
egilkhcommented, Aug 9, 2016
<script type="text/javascript" src="lib/ngStorage/dist/angularLocalStorage.min.js"></script>

This isn’t our ngStorage. Try adding

<script src="https://cdn.jsdelivr.net/ngstorage/0.3.6/ngStorage.min.js"></script>
0reactions
egilkhcommented, Aug 9, 2016

👍

Read more comments on GitHub >

github_iconTop 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 >
Uncaught Error: [$injector:unpr] Unknown provider ...
how to provider is known.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found