gpt4 book ai didi

javascript - AngularJS:有没有更好的方法来同步两个 promise ?

转载 作者:可可西里 更新时间:2023-11-01 02:31:05 25 4
gpt4 key购买 nike

$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();
});
});

最佳答案

是的,您可以使用 $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();
});

关于javascript - AngularJS:有没有更好的方法来同步两个 promise ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18063295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com