Uncaught Error: [$injector:unpr] Unknown provider: $localstorageProvider <- $localstorage

12,561

Solution 1

Change

$localstorage

to

$window.localStorage //S is capitalized

And inject the $window dependancy in your run function.

Solution 2

you are possibly missing a dependency! have a look at e.g. https://github.com/gsklee/ngStorage.

include it into your project and require the ngStorage-module like so:

angular.module('starter', ['ngStorage', 'ionic', 'starter.controllers','ngCordova'])

.run(function($ionicPlatform, $localStorage , $cordovaPush) {
  $ionicPlatform.ready(function() {
    console.log($localStorage); // edit: capital S
  })
})
Share:
12,561
Amy Glenn
Author by

Amy Glenn

Updated on June 15, 2022

Comments

  • Amy Glenn
    Amy Glenn over 1 year

    Was using ionic, in my app.js I do

    angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])
    
    .run(function($ionicPlatform, $localStorage , $cordovaPush) {
      $ionicPlatform.ready(function() {
        console.log($localStorage);
      })
    })
    

    But I got error of Uncaught Error: [$injector:unpr] Unknown provider: $localstorageProvider <- $localstorage

    Any thought? so strange..

    • sp00m
      sp00m almost 8 years
      You're injecting $localStorage but the error message says $localstorage. You're sure about the case?
    • Tarun Dugar
      Tarun Dugar almost 8 years
      Modified my answer. Rectified a simple mistake. It should work now.
  • Jason Spence
    Jason Spence about 7 years
    This solved my issue. I was missing 'ngStorage' in my module.