@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