Reputation: 861
i'm very much new to angular and trying to access localStorage. Here is the code. Please help me figure that out if it is not the right way to define and use. Thank you.
var app = angular.module("toggleApp", ['LocalStorageModule']).config(function (localStorageServiceProvider) {
localStorageServiceProvider
.setPrefix('test')
.setStorageType('localStorage');
});
app.controller("toggleController", function ($scope, $timeout,
timerParsingService, localStorageService) {
localStorageService.set('user' ,'yash');
Upvotes: 2
Views: 4353
Reputation: 6639
you dont require to define any module or inject any other module in the application.
inject $window
in your application and then you can access the localstorage module like this
angular.module('toggleApp', [])
.controller('toggleController', ['$scope', '$window', function ($scope, $window) {
$window.localStorage.setItem('ls', 'test');
}]);
and save the value like this
$window.localStorage.setItem('ls', 'test');
and you can retrieve the localStorage value like this
$window.localStorage.getItem('ls');
Upvotes: 2