title: how can make synchronous promise in angular2
body: <p>I am trying to call a function located in service class,and if that function returns data,one boolean variable sets true. I have 2 class as bollow:student.ts and service.ts:</p>
  
  <p>// student.ts</p>
  
  <pre><code>    public ngOnInit() {
        this.config.load().then(() =&gt; {
  
        this.service.getRecords().then(
           function () { console.log("success getRecord");
                         this.loading = false; },
           function () { console.log("failed getRecord"); 
                         this.loading = true; });
  
      });
    }
  </code></pre>
  
  <p>//service.ts</p>
  
  <pre><code> public getRecord(id: number): Promise&lt;T&gt; {
              return this.getRecordImpl();
  
          }
  
   private getRecordsImpl(): Promise&lt;T[]&gt; {
  
  
  
  
          let url = this.serviceUrl;
  
          return this.http.get(url, this.getRequestOptionsWithToken())
              .toPromise()
              .then(res =&gt; {
                  this.records = this.extractData&lt;T[]&gt;(res);
                  for (var i = 0; i &lt; this.records.length; i++) {
                      var record = this.records[i];
                      this.onRecord(record);
  
                  }
  
                   return this.records;
  
              })
  
              .catch(this.handleError);
  
      }
  </code></pre>
  
  <p>by the now, records from service returns, but this.service.getRecords(); is undefined. and I can't use </p>
  
  <blockquote>
    <p>.then</p>
  </blockquote>
  
  <p>for handling succeed and failure actions. 
  I know that it is not good idea to make it synchronous. but think that being Asynchronous causes getRecords becomes undefined. What is the solution for handling that. I want it runs sequentially. and if service returns any records , variable initialize to false, otherwise it sets to true.</p>
  
  <p>Many thanks for any help and guide.</p>