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



如何使用 AngularJS 将 JSON 从 API 下载到我的本地存储。 我有一个数据数组,我想存储在我的计算机中,但不知道如何保存它。我知道如何获取数据并使用浏览器查看数据

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

您可以将 json 保存在本地存储中,如下所示:

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');

最新更新