admin管理员组文章数量:1399269
I am working on an app that is supposed to filter and sort out data from two json files. The app will have two tables that pare and contrast this data using ngRepeat myData. So far, the top table is already requesting a json file:
app.controller('tableTopController', function ($scope, $http) {
$http.get('first.json').success(function(response){
$scope.myData = response; });
The bottom table is supposed to read data from my second json file: second.json.
I am working on an app that is supposed to filter and sort out data from two json files. The app will have two tables that pare and contrast this data using ngRepeat myData. So far, the top table is already requesting a json file:
app.controller('tableTopController', function ($scope, $http) {
$http.get('first.json').success(function(response){
$scope.myData = response; });
The bottom table is supposed to read data from my second json file: second.json.
Share Improve this question edited Aug 26, 2015 at 18:05 otterblox asked Aug 26, 2015 at 17:34 otterbloxotterblox 291 silver badge6 bronze badges2 Answers
Reset to default 7Try using $q.all()
to resolve both promises and execute a callback function when both are successful. For more info, see the docs.
var promises = [];
promises.push(getFirstJson());
promises.push(getSecondJson());
$q.all(promises).then(function (results) {
var firstJson = results[0];
var secondJson = results[1];
});
function getFirstJson() {
return $http.get(...);
}
function getSecondJson() {
return $http.get(...);
}
If you want to wait for the first call to plete before you get the second file and if you want to ensure everything is loaded before paring and contrasting:
app.controller('theController', function ($scope, $http) {
$http.get('first.json').success(function(response){
$scope.firstData = response;
$http.get('second.json').success(function(response1){
$scope.secondData = response1;
//add any other logic you need to do here to pare & contrast
//or add functions to $scope and call those functions from gui
});
});
});
Or, call them sequentially but then you need to ensure your paring and contrasting can't start until both are loaded:
app.controller('theController', function ($scope, $http) {
$http.get('first.json').success(function(response){
$scope.firstData = response;
});
$http.get('second.json').success(function(response1){
$scope.secondData = response1;
});
//add any other logic you need in functions here to pare & contrast
//and add those functions to $scope and call those functions from gui
//only enabling once both firstData and secondData have content
});
本文标签: javascriptAngularJs How to call multiple json files to tables using httpgetStack Overflow
版权声明:本文标题:javascript - AngularJs: How to call multiple json files to tables using http.get - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744161436a2593354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论