从angularjs中的api请求将json下载到本地存储

从angularjs中的api请求将json下载到本地存储,angularjs,json,api,storage,Angularjs,Json,Api,Storage,如何使用angularjs将json从api下载到本地存储。 我有一个数组的数据,我想存储在我的电脑,但不知道如何保存它。我知道如何获取数据并在浏览器中使用 angular.module("myModule",[]) .controller('myController',['$scope','$http',function(response){ $http.get(json file url).then(function(response){ console.log(response

如何使用angularjs将json从api下载到本地存储。 我有一个数组的数据,我想存储在我的电脑,但不知道如何保存它。我知道如何获取数据并在浏览器中使用

angular.module("myModule",[])
.controller('myController',['$scope','$http',function(response){
  $http.get(json file url).then(function(response){
    console.log(response)
  })

}])

您可以将json保存在localstorage中,如下所示:

angular.module("myModule",[])
.controller('myController',['$scope','$http',function(response){
  $http.get(json file url).then(function(response){
    localStorage.setItem('jsonResult', response);
  })
}])
在获得价值的同时,您可以:

var response = localStorage.getItem('jsonResult');