在我的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
有什么想法?太奇怪..
答案 0 :(得分:9)
将它包含在您的项目中并需要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');