Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70764

Subscribe inside Promise

$
0
0

@nairdagui wrote:

Hi. My app checks if there are data in Ionic Storage and if there are none, it will load data from a JSON file to the Ionic Storage. This are my code:

quote.page.ts

quotes: Quote[] = [];

this.plt.ready().then(() => {
      this.storageService.loadQuotes().then(quotes => {
        this.quotes = quotes;
      });
    });

storage.service.ts

quotes: Promise<Quote[]>;
data: any;

loadQuotes(): Promise<any> {
    return this.storage.get(QUOTES_KEY).then((quotes: Quote[]) => {
      if (!quotes || quotes.length === 0) {
        this.http.get("../../assets/files/quotes.json").subscribe(result => {
          this.data = result["quotes"];
          this.quotes = result["quotes"];
          this.storage.set(QUOTES_KEY, this.data);
          return this.quotes;
        });
      }
    });
  }

My problem is, there are no data loaded in quotes in the quote.page.ts but data was loaded in the ionic storage.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70764

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>