2017-07-18 82 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');