angularjssessionangular-local-storage

How to Store angularJS data into local Storage as like Session?


How to Store angularJS Variable Data into local temp storage for further usage as like session in server side.

The AngularJS Source Code is

var pApp = angular.module('ProfileIndex', []);
pApp.controller('ProfileIndexCtrl', function($scope, $http, $cacheFactory) {
  $scope.data = "MVVM";
});

How to Store the MVVM value in the local storage? and how to retrieve the value from the local storage?


Solution

  • Simply use the web storage API

    // set "data" to "MVVM"
    $window.localStorage.setItem('data', 'MVVM');
    
    // get "data"
    $window.localStorage.getItem('data');