I am retrieving data from storage. I can retrieve it just fine, however the view renders before the promise is resolved so it doesn’t display any data. I know that the data is retrieved because I am logging it.
storage provider
getData(): any {
let data = [];
return this.storage.forEach((value, key, index) => {
if (key.startsWith("KEY-")) {
data.push(value);
}
}).then(() => data);
}
component.ts
let test = this.storage.getSessionData().then((data) => {
this.dataArr = data;
// Shows data
console.log("data", this.dataArr);
});
// Shows empty
console.log("data", this.dataArr);
html
<ion-list>
<ion-list-header> Data </ion-list-header>
<ng-container *ngIf="data && data.id; else noData">
<ion-item *ngFor="let d of data" text-wrap>
{{d.id}}
</ion-item>
</ion-list>
<ng-template #noData>
<ion-list>
<ion-list-header> Data </ion-list-header>
<ion-item>No Data</ion-item>
</ion-list>
</ng-template>