title: Angular / Typescript Promises
body: <p>I've got myself tangled up in Promises. I want to wait until checkNewVersion() has finished and then execute the then statement, but at the moment, 'finished' gets called first then 'api response'</p>
  
  <p>page.ts</p>
  
  <pre><code>public ionViewDidLoad() {
      this.platform.ready()
          .then(() =&gt; {
              this.versionChecker.checkNewVersion()
                  .then(response =&gt; {
                      console.log('finished')
                  })
          });
  }
  </code></pre>
  
  <p>version-checker.ts</p>
  
  <pre><code>public checkNewVersion(force?: boolean): Promise&lt;CheckResult&gt; {
  let platform = this.platform.is("ios") ? 'ios' : 'android';
  if (force || this.shouldCheck()) {
      return  this.checkPromise = this.api.post('check-version', {platform: platform, version: '0.2.1'})
    .then(response =&gt; {
        console.log('api response')
        let result = {
            latest: response.latest,
        }
      return result;
    });
  }
  return this.checkPromise;
  }
  </code></pre>
  
  <p>api-service.ts</p>
  
  <pre><code>public post(path: string, body: any): Promise&lt;any&gt; {
      //add location if we have it.
      let postBody = {...body};
      postBody.locationInfo = this.locationService.getUpdatedLocation();
  
      return this.http.post(this.settings.api + path, postBody, { headers: this.headers })
          .map((res: Response) =&gt; { return res.json(); })
          .catch((err: Response, obs: Observable&lt;any&gt;) =&gt; {
              return this.handleError(err, obs);
          })
          .toPromise();
  }
  </code></pre>