【发布时间】:2019-10-20 00:32:02
【问题描述】:
我的应用程序检查 Ionic Storage 中是否有数据,如果没有,它会将数据从 JSON 文件加载到 Ionic Storage。这是我的代码:
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;
});
}
});
}
我的问题是,quote.page.ts 中的引号中没有加载数据,但数据已加载到离子存储中。
【问题讨论】:
标签: angular ionic-framework ionic4