AngularJS and issue with $localStorage from ngStorage : Error: [$injector:unpr] Unknown provider:

user1713964 picture user1713964 · Aug 28, 2014 · Viewed 9.9k times · Source

It looks like my issue is quite simple (i'm probably dumb ;) ) but couldn't point it out.

I found some topics about the same issue I have about localStorage (using ngStorage) on Angular but I can't understand why this syntax doesn't work :

 function myCtrl($scope, $http, $resource, $storage, $localStorage) {
   ....
 }

 myCtrl.$inject = ['$scope', '$http', '$resource', '$storage', '$localStorage'];

Also I defined as well the app in app.js (after installing ngStorage) :

 angular.module('onBoardingApp', ['ngStorage', 'ngResource']);

this generates this kind if error :

 Error: [$injector:unpr] Unknown provider: $storageProvider <- $storage

some are using the injection via angular.module (I tried it without any success)

 angular.module('app', [
   'ngStorage'
 ]).controller('myCtrl', function(
   $scope,
   $localStorage
 ){
  //foo
 });

EDIT

I finally get through this issue by using another factory : $store. Here is the source I used to make it work : http://jsfiddle.net/agrublev/QjVq3/

Answer

Joshua Barker picture Joshua Barker · Feb 8, 2015

I may be mistaken, but it looks like you are not passing the correct reference to your controller. The correct usage is just $sessionStorage or $localStorage. The $storage reference you are using appears to be incorrectly taken from the examples on the GitHub page, and your code is blowing up because there is no actual $storage provider.