Anita Mehta Anita Mehta - 1 year ago 192
AngularJS Question

How to save json response in local storage using angularjs?

I have api which return json response and I want to store that json response in localstorage to use that response in my another html page using angularjs.

Here is my code which return json response....

QAApp.controller('SearchCtrl', function ($scope, $http, $location) {

$ = function (searchtag) {
var request = $http({
method: 'GET',
url: server + 'api/question/tagged/' + searchtag,
request.success(function(data, status, headers, config) {
$ = data;


Please tell me how can I store it...

Answer Source

On your request.success(),use

window.localStorage['storageName'] = angular.toJson(data);

Then you can access the data in localstorage by

var accessData = window.localStorage['storageName'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download