user1713964
user1713964

Reputation: 1249

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

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/

Upvotes: 1

Views: 9973

Answers (3)

MK_Canada
MK_Canada

Reputation: 1

Use ngStorage in your application for data persistence, here whenever you restart your application the data will persists. ngStorage stores the data in the same location where HTML5 local storage would store. This is only a wrapper for local storage. Whereas, Local storage is stored in your browser so as long as you don't clear your data it will be there forever. In this case there might be some logic problem with resetting server data.

Upvotes: 0

Joshua Barker
Joshua Barker

Reputation: 1007

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.

Upvotes: 2

silvster27
silvster27

Reputation: 1936

Try clearing your browsers history. If the controller already has a localStorage variable for that controller and it conflicts with the new localStorage variable you can receive this error.

Upvotes: 0

Related Questions