1
기능 one
은 two
으로 값을 전달하고 two
은 three
으로 값을 전달합니다. 이 함수들 중 어떤 것도 데이터를 반환하기 위해 어느 정도의 시간이 걸릴 수 있습니다. 앞을 서두르고 undefined
을 인쇄하는 대신에 어떻게 가치를 기다리게 할 수 있습니까?AngularJS : Seqential 약속 체인
var deferred = $q.defer();
var one = function (msg) {
$timeout(function() {
console.log(msg);
return "pass this to two";
}, 2000);
};
var two = function (msg) {
console.log(msg);
return "pass this to three";
};
var three = function (msg) {
console.log(msg);
};
deferred.promise
.then(one)
.then(two)
.then(three);
deferred.resolve("pass this to one");
훌륭한 작품. 감사. –