$http.get('/services/menu').success(function (dataMenu) {
$http.get('/services/language').success(function (dataLanguage) {
console.log('dataLanguage', dataLanguage);
$scope.menuRoot = dataMenu.result.items;
$scope.menuItems = dataMenu.result.items;
$scope.languageRoot = dataLanguage.result;
$scope.currentMenuItem = null;
$scope.refreshExperiments();
$scope.mergeLanguage();
});
});
问问题
4935 次
2 回答
25
是的,您可以使用以下命令并行运行它们$q.all
:
$q.all([$http.get('/services/menu'), $http.get('/services/language')])
.then(function (res) {
var dataMenu = res[0].data.result.items;
console.log('dataLanguage', res[1].data);
$scope.menuRoot = dataMenu;
$scope.menuItems = dataMenu;
$scope.languageRoot = res[1].data.result;
$scope.currentMenuItem = null;
$scope.refreshExperiments();
$scope.mergeLanguage();
});
于 2013-08-05T16:45:44.233 回答
0
或者:
var menuPromise = $http.get('/services/menu');
var languagePromise = $http.get('/services/language');
menuPromise.success(function(dataMenu) {
languagePromise.success(function(dataLanguage) {
console.log('dataLanguage', dataLanguage);
$scope.menuRoot = dataMenu.result.items;
$scope.menuItems = dataMenu.result.items;
$scope.languageRoot = dataLanguage.result;
$scope.currentMenuItem = null;
$scope.refreshExperiments();
$scope.mergeLanguage();
});
});
它同时发出两个$http
请求,然后在两个承诺都得到满足后运行代码块 ( console.log... etc
) 。$http
于 2015-09-17T17:26:19.500 回答