How to use SessionStorage in Angular JS

How to use SessionStorage in Angular JS

SessionStorage is similar to localstorage, except that data is stored in sessionstorage but it expired. When data is stored in localstorage, data will not expire even when the browser will end ( i. e when the browser is closed )
The sessionStorage is cleared, if we close the tab, Close the browser. If we set data in chrome that data is not available on Firebox. Even that that data is not available on chrome next tab.  


Exmaple :


    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', ["ngStorage"])
        app.controller('MyController', ['$scope', '$localStorage', '$sessionStorage', '$window',function ($scope, $localStorage, $sessionStorage, $window) {
            $scope.Save = function () {
                $localStorage.LocalMessage = $scope.myname;
            $scope.Get = function () {
    <div ng-app="MyApp" ng-controller="MyController">
<input type="text" name="myname" ng-model="myname">
        <input type="button" value="Save" ng-click="Save()" />
        <input type="button" value="Get" ng-click="Get()" />


Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed