I have 4+ experience and working as software Engineer with Hytech professionals India PVT ltd and also working as Consultant,Trainer,Blogger and Author on Microsoft technologies,Also I have Trained more than 500+ IT professionals.I have knowledge about Asp.net,C#,SQL,Project management,replication,MVC,WebApi,SSRS,PostMan,TFS,SVN,Swagger,WMI,Agile,SignalR,Angularjs,IIS configuration.

How to save information on client side using Angularjs?

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.
setitem:- localStorage.setItem('history',JSON.stringify(oldItems));
// olditem ==Your object value or information
getitem :-
//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, 20 June 2016

1 comments for "How to save information on client side using Angularjs?"

Life Is Complicated, But Now programmer Can Keep It Simple.