Hello, I’m trying to load a data list (similar to the list in the Super Starter), but initially from Storage
. Any help would greatly be appreciated
What I’m Trying to Do
Initially the list is empty, so pulling from Storage loads nothing. But after the user adds a new item, it saves to Storage. Even after killing the app, the user should open it back up to their list of items they created
What Happens Now Instead
Currently, I seem to have it almost working, but when opening the app after killing it, the empty list shows. If I then go to the list in the app (click the navigation to it again), all the items from Storage show as desired.
Question
How do I pre-load my list from Storage so that the empty list state does not show to the user? (It seems that my app is loading before the Storage promise returns…)
Code Currently
app.component.ts - calling my provider’s load
constructor(public platform: Platform, public statusBar: StatusBar,
public splashScreen: SplashScreen,
public districtService: DistrictService) {
this.initializeApp();
districtService.load();
}
district.service.ts - the load function
districts: District[] = [];
constructor(public storage: Storage) { }
load() {
this.storage.get('districts').then((districts) => {
if(districts) this.districts = districts;
});
}
So for the short, where and when would you load from Storage if you were doing this in the SuperStarter (since that’s what my code is based off of)?
Thanks!