1
I’m starting with Ionic 2, which uses Angular 2, and I’m trying to understand how Promises work, because some libs I’m using work have functions that return Promises and would like to get the value returned, however the return is always Undefined:
Ex.:
'class' Storage:
public get(key: string) {
localforage.getItem(key).then(function (value) {
console.log(value); // exibe o value normalmente, ex.: {nome: 'Joao', idade: '20'}
return value;
}).catch(function (err) {
console.log(err);
});
}
'class' Page1:
recuperarItem() {
var object = this.storage.get('pessoa1');
console.log(object); // undefined
}
How do I get the return this way? Thank you for your attention.
Wouldn’t that be the part
localforage
? The correct is localStorage– Laerte
I’m using the localforage library in this example - https://mozilla.github.io/localForage/ - but the doubt would apply to any Promise
– Renan Baggio