Search code examples
angularjslocalforage

locaforage getItem() is not executing


$localForage.getItem('brandChainNames', function(err, data) {
    // The same code, but using ES6 Promises.
    console.log('_storedValue: '+ data);
});

There is no key so far (verified in tools-> storage perspective). But that console output does not print anything (in firefox). Could someone tell me what could be the problem. console output before and after it, prints fine.

EDIT: modified the code like:

var hallabolo = $localForage.getItem('brandChainNames', function(err, data) {
    // The same code, but using ES6 Promises.
    console.log('_storedValue: '+ data);
});

angular.toJson(hallabolo) prints {}
tried with:
1.JSON.stringify(hallabolo)=='{}'// returns false
2.Object.keys(hallabolo).length // returns 1
3. jQuery.isEmptyObject(hallabolo)// returns false
4. angular.isObject(hallabolo)// returns true

Not to mention type of 'undefined', null etc does not work as hallabolo is an object


Solution

  • $localForage.getItem('brandChainNames', function(err, data) {
        // The same code, but using ES6 Promises.
        console.log('_storedValue: '+ data);
    });
    

    is not working but following is working:

    $localForage.getItem('brandChainNames').then(function(data) {
        // The same code, but using ES6 Promises.
        console.log('_storedValue: '+ data);// data is printed as undefined, as expected
    });
    

    Anyone, why?