未捕获错误:[$ injector:unpr]未知提供者:$ localstorageProvider< - $ localstorage

时间:2015-11-17 14:29:44

标签: javascript angularjs ionic

在我的app.js中使用离子,我做

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

.run(function($ionicPlatform, $localStorage , $cordovaPush) {
  $ionicPlatform.ready(function() {
    console.log($localStorage);
  })
})

但我收到了Uncaught Error: [$injector:unpr] Unknown provider: $localstorageProvider <- $localstorage

的错误

有什么想法?太奇怪..

3 个答案:

答案 0 :(得分:9)

你可能错过了依赖!看看例如https://github.com/gsklee/ngStorage

将它包含在您的项目中并需要ngStorage模块,如下所示:

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

.run(function($ionicPlatform, $localStorage , $cordovaPush) {
  $ionicPlatform.ready(function() {
    console.log($localStorage); // edit: capital S
  })
})

答案 1 :(得分:4)

更改

$localstorage

$window.localStorage //S is capitalized

并在运行函数中注入$window依赖项。

答案 2 :(得分:0)

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

    .run(function($ionicPlatform, $localStorageProvider , $cordovaPush) {  $ionicPlatform.ready(function() {
console.log($localStorageProvider);
 })
})

从localstorage获取以前保存的密钥,如下所示

    $localStorageProvider.get('YOUR_KEY'); 

请参阅https://github.com/gsklee/ngStorage