This my code:
angular.module('MyModule').controller('MyController', ['$scope', '$stateParams','$location', '$http','LocalStorageModule',
function($scope, $stateParams, $location, $http, localStorageService) {
localStorageService.add('test', 'val');
]);
any Idea whats wrong?
I'm getting exception - unknown provider localstorageservice in the FF browser
Firebug Error
Error: [$injector:unpr] Unknown provider: LocalStorageModuleProvider <- LocalStorageModule
http://errors.angularjs.org/1.2.20/$injector/unpr?p0=LocalStorageModuleProvider%20%3C- %20LocalStorageModule
at http://127.1.0.0/lib/angular/angular.js:78:12
We should ask inejctor for 'localStorageService'
instead of your 'LocalStorageModule'
So the code should look like this:
angular
.module('MyModule')
.controller('MyController', ['$scope', '$stateParams','$location'
, '$http'
// instead of this
// ,'LocalStorageModule',
// use this
,'localStorageService',
function($scope, $stateParams, $location, $http, localStorageService)
{
//localStorageService.add('test', 'val');
localStorageService.set('test', 'val');
}]);
And when we do initialize the module, we have to include the local storage module
angular
.module('MyModule', [
'LocalStorageModule',
...
])
And also as documented here:
we should use .set()
// To add to local storage
localStorageService.set('localStorageKey','Add this!');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With