Today we are implementing exceptionally straightforward case of how to save object value or any information on client side using in AngularJS.There are many options to store information.
2:- Same like this you can use "sessionstorage" :-
Note :-Don't forget to add respective directive for storage option.best option is localstorae than other.
localStorage vs. sessionStorage vs. Cookies:-
As far as abilities, Cookies just permit you to store strings. sessionStorage and localStorage permit you to store JavaScript primitives yet not Objects or Arrays (it is conceivable to JSON serialize them to store them utilizing the APIs). Session stockpiling will by and large permit you to store any primitives or items upheld by your Server Side dialect/system.
1:-LocalStorage:-
setitem:- localStorage.setItem('history',JSON.stringify(oldItems)); // olditem ==Your object value or information getitem :- localStorage.getItem('history'); //history is key Remove item:- $scope.RemoveHistory = function (item,index) { var historyData = localStorage.getItem('history'); var parsedData = JSON.parse(historyData); for (i = 0; i < parsedData.length; i++) { //check condition (optional) if (parsedData[i].UserName === item.UserName && parsedData[i].source === item.source && parsedData[i].destination === item.destination) { parsedData.splice(i, 1); //Remove item using index and set again in same key "history". localStorage["history"] = JSON.stringify(parsedData); } }
2:- Same like this you can use "sessionstorage" :-
sessionStorage.setItem('key', 'value');
var data = sessionStorage.getItem('key');3:- Window storage :-
window.localStorage.setItem("key", Value);
var data=window.localStorage.getItem("UserToken");4:-Cookies storage
angular.module('cookiesExample', ['ngCookies']) .controller('ExampleController', ['$cookies', function($cookies) {
// Retrieving a cookie
var favoriteCookie = $cookies.get('myFavorite');
// Setting a cookie
$cookies.put('myFavorite', value);
}]);Use $cookiesProvider to change the default behavior of the $cookies service.
Note :-Don't forget to add respective directive for storage option.best option is localstorae than other.
localStorage vs. sessionStorage vs. Cookies:-
As far as abilities, Cookies just permit you to store strings. sessionStorage and localStorage permit you to store JavaScript primitives yet not Objects or Arrays (it is conceivable to JSON serialize them to store them utilizing the APIs). Session stockpiling will by and large permit you to store any primitives or items upheld by your Server Side dialect/system.


