0
@track var

function1() {
   function2();
   console.log(var); 
}
function2() {
   var = 2;
}

For function 2 i am querying a controller to get related data, but when I test the output, the results are blank as the console.log hasn't got the var variable yet. How do i wait for function2 to finish before proceeding with the next lines of code so the variables aren't empty?

2
  • Yes thank you, but how can it await on a function finish other than a timer?
    – CalDe
    Oct 13, 2022 at 11:23
  • take a look at the accepted answer on that post. you have to use the await keyword on the apex method you are querying the record from. in your case, should be something like: this.records = await YourApexMethodHere(); (also try not to use reserved words as your variable names, ie: var) here you can find another sample code
    – McCubo
    Oct 13, 2022 at 11:35

0

Browse other questions tagged .