I'm starting with Ionic 2, which uses Angular 2, and I'm trying to understand how promises work, since some libs I'm using work have functions that return promises and would like to get the value returned, but 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 return this way? Thank you for your attention.