title: How to wait for a asynchronous method execution and then execute synchronous statements in angular7
body: <p>I googled a lot on how to wait for asynchronous and then execute synchronous in angular7, but no luck so far. 
  in my component I have two methods loadList() simpleMethod_1().</p>
  
  <p>On a click event simpleMethod_1() is triggered which then calls loadList() </p>
  
  <p>I tried to use angular async-await, but didn't work or may be I didn't configure it in a right way!!
  I also tried setting timer which works the way I want to ( line number 7-10 executes), but when the internet is very slow then it fails.</p>
  
  <pre><code>loadList() {
      this.loadingGif = true;
      this.service.resetAllStoredData(); 
      // get the list data from server
      this.service.getAllList().subscribe(list =&gt; {
        this.list = list;
        // save the list so as to retrieve again
        this.service.setList(list); //sync
        this.loadingGif = false; 
      });
    }
  
  
  simpleMethod_1(){
  
    1. const storedId = this.localStroageService.getStoredId();
    2. this.loadList();   
    3. console.log("aap loading 1", this.loadingGif)
  
      4. if (
        storedId !== null &amp;&amp;
        storedId !== undefined 
      ) {
        5. console.log("aap loading 2", this.loadingGif)
  
        6. if (!this.loadingGif) {
          // check before navigating
          7. const data = this.list.find(item =&gt; item.id === storedId );
  
           8. if (!data.complete) {
            // remember to store routing info
            // fetch user data 
           9.  this.getUserDetails();//synchronous
  
           10.  this.router.navigate("somepath")
          }
        }//end of loadingGif if
  
      }
  }//end of method
  </code></pre>
  
  <p>(NOTE: I purposely gave numbers so I can point out what I'm talking)</p>
  
  <p>ISSUE: 
  What happens is whenever simpleMethod_1() is called,  after line #1, asynchronous method loadList() gets called and the lines 3-5 gets executed before even loadList() finishes execution! And because loadingGif is still true, line number 7-10 never executes. </p>
  
  <p>What I want to achieve is, simpleMethod_1() will be triggered,
  - line 1 executes,
  - should call loadlist() and wait till it finishes and then come out from there
  -and then execute line 3, 4, 5, 6, 7, 8, 9, 10 ...at end it should navigate to different page</p>
  
  <p>Could anyone suggest how can I achieve this?</p>