I have some problems with ionic storage


#1

im still learning so i need help
when im trying to get data to my HomePage view nothimng happens…
there is my small project


#2

Please link to where you added the storage code - I couldn’t find it and wasted time.


#3

i accidentally linked the wrong project… (fixed)

sorry.


#4

I don’t see where you set your places array. I assume that’s what your going for in ionViewWillEnter, but it won’t automatically set it when loading from storage.

So you’ll need to change it to something like:

ionViewWillEnter() {
    if(!this.places) {
        this.storage.get('places').then(places => this.places = places);
    }
}

#5

i tried your code and im still getting an empty array when loading the app…

when i checked the storage in the inspect i can see the im storing the array im writing.

seem like the problem is retrieving the array once i stored it…

i think there is a problem with the storage plugin because i remember that i made it work few months ago…


#6

Lots of us are using Ionic Storage with zero problems, whereas none of us aside from you are using your app code, so I’m pretty sure the problem is in your app code and not with Storage itself.

You never call storage.get(), because an empty array is still truthy.


#7

I think there’s actually nothing wrong with the storage plugin, but with your code. Little bit hard to tell since the repo you gave isn’t useable because it seems to be missing lots of components and pages. So the million dollar question is, where are you setting this ‘places’ the very first time? It’s impossible to tell without a full repo or good explanation to solve your problem I’m afraid.


#8

i made it ! the problem was that i wasn’t calling the get function the right way…

thanks guys for trying to help !


#9

No it wasn’t. As I said earlier, the problem was that you were never calling the get function at all, because you were wrongly assuming that an empty array is falsy.