네 가지 응답의 약속을 가져야하지만이 작업을 수행하려면 먼저 모든 함수를 처음부터 끝까지 순서대로 호출해야합니다. 내 코드에서 마지막 호출 된 함수의 약속 콜백에서 다음 함수를 호출한다는 것을 알 수 있습니다.순차적 약속
코드가 적절하지 않으므로이를 수행하는 데 더 좋은 방법이 있는지 알아야합니다.
제안 사항? 대신이 일을
$scope.createPayment = function() {
var dados = $scope.card;
// get first promise
PagamentoMP.createToken(dados)
.then(
function(result) {
dados.token = result;
// get second promise
PagamentoMP.guessPaymentMethod(dados)
.then(
function(result) {
dados.paymentMethod = result;
// get third promise
PagamentoMP.getIssuers(dados)
.then(
function(result) {
dados.issuer = result;
// get fourth promise
PagamentoMP.getInstallments(dados)
.then(
function(result) {
dados.installments = result;
},
// error for fourth promise
function(result) {
console.log("getInstallments PAGAMENTOMP -> Failed to get the name, result is " + result);
}
);
},
// error for third promise
function(result) {
console.log("getIssuers PAGAMENTOMP -> Failed to get the name, result is " + result);
});
},
// error for second promise
function(result) {
console.log("guessPaymentMethod PAGAMENTOMP -> Failed to get the name, result is " + result);
});
},
// error for first promise
function(result) {
console.log("createToken PAGAMENTOMP -> Failed to get the name, result is " + result);
});
};
약속을 반환하는 기능을 제어 할 수 있는지 여부는 확실하지 않습니다. 당신이 그렇게한다면 비동기적인 것들을 피할 수 있도록 그들을 재 작업하는 것을 고려할 것입니다. 약속을 한 번 이상 중첩해야한다면 항상 붉은 깃발을 생각하고 있습니다. –