javascript 未捕获的错误:[$injector:unpr] 未知提供者:$localstorageProvider <- $localstorage
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33759455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught Error: [$injector:unpr] Unknown provider: $localstorageProvider <- $localstorage
提问by Amy Glenn
Was using ionic, in my app.js I do
使用 ionic,在我的 app.js 中
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
但我得到了错误 Uncaught Error: [$injector:unpr] Unknown provider: $localstorageProvider <- $localstorage
Any thought? so strange..
任何想法?这么奇怪..
回答by pierrebeitz
you are possibly missing a dependency! have a look at e.g. https://github.com/gsklee/ngStorage.
您可能缺少依赖项!看看例如https://github.com/gsklee/ngStorage。
include it into your project and require the ngStorage-module like so:
将它包含到您的项目中并像这样需要 ngStorage-module:
angular.module('starter', ['ngStorage', 'ionic', 'starter.controllers','ngCordova'])
.run(function($ionicPlatform, $localStorage , $cordovaPush) {
$ionicPlatform.ready(function() {
console.log($localStorage); // edit: capital S
})
})
回答by Tarun Dugar
Change
改变
$localstorage
to
到
$window.localStorage //S is capitalized
And inject the $window
dependancy in your run function.
并$window
在您的运行函数中注入依赖项。
回答by bisi
angular.module('starter', ['ionic', 'starter.controllers','ngCordova','ngStorage'])
.run(function($ionicPlatform, $localStorageProvider , $cordovaPush) { $ionicPlatform.ready(function() {
console.log($localStorageProvider);
})
})
to get a previously saved key from localstorage use as follows
从 localstorage 中获取以前保存的密钥,如下所示
$localStorageProvider.get('YOUR_KEY');