title: Angular Component not getting proper data from Service
body: <p>I think I understand the issue I am having, yet am having a hard time figuring out the best solution. I have an Ionic / Angular app which makes API calls through a variety of Service classes, all of these Service classes are called by a parent &quot;DataService&quot; class.</p>
  <p>Once a user logs into my application, they are redirected to a &quot;TaskList&quot; component. This component calls <code>DataService.getData()</code> which should populate several arrays within DataService with the appropriate data. This code can be seen below:</p>
  <pre><code>export class TaskListPage implements OnInit {
      ...
      ngOnInit() {
      this.dataService.getData().then(() =&gt; {
        this.workOffers = this.dataService.getWorkOffers();
        this.confirmedWorkOrderDates = this.dataService.getConfirmedWorkOrderDates();
        console.log(&quot;Client Task List WO: &quot; + JSON.stringify(this.workOffers));
      });
    }
  }
  </code></pre>
  <p>However, upon the page being loaded, the workOffers array is empty [] as can be seen from the console.log line.</p>
  <p>I know this is because the TaskListPage is somehow calling DataService.getWorkOffers() before DataService has had a chance to store any daya within that array. I've tried adding promises to the getData function to force the execution of getWorkOffers() to happen after getData is done executing, but it doesn't work.</p>
  <p>Here is DataService.getData():</p>
  <pre><code>getData() {
      return new Promise&lt;void&gt;((resolve) =&gt; {
        this.workOffers = new Array();
        this.updates = new Array();
        this.tasks = new Array();
        this.shifts = new Array();
        this.confirmedWorkOrderDates = new Array();
        // Get USER object of user logged in
        this.userService.getUser(this.currentUserId).subscribe(async (user: User) =&gt; {
          this.userLoggedIn = user;
          this.currentUserId = user.id;
    
         
          this.getClientData().then(() =&gt; {
              resolve();
          });
          }
        });
      });
    }
  </code></pre>
  <p>getClientData is another method that calls several other service classes:</p>
  <pre><code>getClientData() {
      return new Promise&lt;void&gt;((resolve) =&gt; {
        this.workOfferService.getClientBookedOffers(this.currentUserId)
          .subscribe((workOffers: WorkOffer[]) =&gt; {
            for (let wo in workOffers) {
              // Push workOffer to array
              this.workOffers.push(workOffers[wo]);
              ...[ More Service calls]
            }
          });
          resolve();
      });
    }
  </code></pre>
  <p>I must be using the Promises incorrectly, because from what I understand getData should finish executing (and thus populate DataService.workOffers[]) before TaskList calls getWorkOffers.</p>