Answer the question
In order to leave comments, you need to log in
Promise: How to pass parameter then(param) further down the chain?
Provided that in the first then it is necessary to return Promise. Without it, it is clear how to convey.
...
.then(function(param1) {
...
return Promise;
})
.then(function(param2) {
// здесь нужно иметь доступ к значению param1 из предыдущего then
})
Answer the question
In order to leave comments, you need to log in
.then(function(param1) {
...
return Promise.all([
Promise.resolve('val1'),
param1
]);
})
.then(function(arr) {
var param2 = arr[0]
, param1 = arr[1]
})
Pass it as an argument when resolving a promise:
jsfiddle.net/koceg/b23xgbLy/1
What about
var param1;
// ...
.then(function(p1) {
param1 = p1;
// ...
return Promise;
})
.then(function(param2) {
console.log(param1, param2);
})
Looks like I found a way:
...
.then(function(param1) {
...
Promise.then(function(param2) {
return {param1: param1, param2: param2};
});
return Promise;
})
.then(function(params) {
// params.param1, params.param2
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question