0

If I have the following code:

Meteor.call('/firstURL/abcd', xxx, function(err, result) {          
    if (err) {
        //...
    } else {    
        Meteor.call('/secondURL/acde', zzz,  function(err, result) {
            if (err) {
                //..
            } else {  
                valueneeded=result
            } 
        });             
    }           
});
console.log(valueneeded)       //undefined

How to get variable

valueneeded

outside the asynchrnous call ?

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59
user3405478
  • 47
  • 1
  • 9

1 Answers1

0

See also Blaze template iterate over object (also applicable to any situation, not just within a Blaze template)

With Meteor, you can also use a ReactiveVar to receive the result of your asynchronous call. If your code that makes use of it is within a reactive scope (like a Tracker.autorun), it will be re-executed when data arrives.

This assumes that you can live with that code being executed several times (initially while your call is still pending a response, then once it completes)

ghybs
  • 47,565
  • 6
  • 74
  • 99