I have data stored using custom keys. I want to return all data that starts with the id KEY- so I loop over all the data and storage and push the ones that match into an array. I can see that the data is being pushed into data[]
but when I call getData() in my component it returns an empty array. What am I doing wrong?
storage.ts
getData(): any {
this.storage.ready().then(() =>
{
let data = [];
this.storage.forEach((value, key, index) =>
{
if (value.id.startsWith("KEY-")) {
data.push(value);
console.log(data);
}
});
return data;
});
}
component.ts
ionViewDidLoad() {
this.data = this.storage.geData();
}
I've also tried this way
ionViewDidLoad() {
this.storage.getData().then(data => console.log(data));
}
returnstatement is in the wrong place. I would think you need to move it down a line so it's just outside the closing function bracket.