我有 3 个通过 $http 进行的网络请求,该请求位于函数中 (function1()
, function2()
, function3()
) 。我想自定义所有这些请求的执行顺序。
object.function1().then(function() {
//result of petition $http of function1();
});
object.function2().then(function() {
//result of petition $http of function1();
});
object.function3().then(function() {
//result of petition $http of function2();
});
他们都尝试同时运行。有些请求比其他请求花费更长的时间,因为它们获取更多 JSON 对象。我想先运行:
function1(); //first
function2(); //second
function3(); //three
最佳答案
您需要正确使用.then()
方法:
object.function1().then(function(result) {
//result of petition $http of function1();
return object.function2()
}).then(function (result) {
//result of petition $http of function2();
return object.function3();
}).then(function (result) {
//result of petition $http of function3();
});
关于javascript - 在 Angular.js 中对 $http 请求的结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37582786/