title: Angular 2 Observable Service to return data from localStorage
body: <p>I am after extending a Observables service to return data from local storage.</p>
  
  <p>Scenario:
  Component will subscribe to Service.GetAll() and GetAll() will look up in the localStorage for data if found it will return else it will make a api call to get the data.</p>
  
  <p>I managed to do this using Promise, but I prefer to convert it to Observables</p>
  
  <pre><code>getAll(): Promise&lt;IScheduleFrequency[]&gt; {
      let ScheduleFrequencies: IScheduleFrequency[] = this.storageService.get('ScheduleFrequencies');
      if (ScheduleFrequencies != null) {
          return Promise.resolve(ScheduleFrequencies);
      } else {
          return this.http.get(this.apiUrl)
              .toPromise()
              .then((response) =&gt; {
                  let ScheduleFrequencies: IScheduleFrequency[] = response.json();
                  this.storageService.save('ScheduleFrequencies', activityScheduleFrequencies);
                  return ScheduleFrequencies || [];
              })
              .catch(this.handleError);
      }
  }
  </code></pre>
  
  <p>Appropriate if some one can show me how I can extend below service to do the same.</p>
  
  <pre><code>getAll(): Observable&lt;TransactionStatus[]&gt; {
      return this.http.get(this.apiUrl)
          .map(this.extractData)
          .catch(this.handleError);
  }
  </code></pre>
  
  <p>Thank you
  Asanka</p>
  
  <p><strong>Update</strong>
  Thank you @nzjun90 for the reply it works need to import 'of'
  import 'rxjs/add/observable/of';</p>