2017-07-18 59 views
0

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

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

}]) 

回答

0

查看它在浏览器中,您可以保存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'); 
相关问题