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.
You have just read an article that categorized by title Angular /
AngularJs
by title How to save information on client side using Angularjs?. You can bookmark this page with a URL https://bikeshsrivastava.blogspot.com/2016/06/part-19how-to-save-information-on.html. Thank You!
Author:
Bikesh Srivastava - Monday, June 20, 2016
Nice Blog
ReplyDeleteangularjs training in Bangalore
angularjs training institutes in Bangalore
best angularjs training in Bangalore
Thanks for sharing this worthful article. Thank you.
ReplyDeleteFull Stack online Training
Full Stack Training
Full Stack Developer Online Training
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Full Stack Training Institute