0

I have a cart service where I want to store and get items from it. I can store however the get returns a promise.

How do I get the data? How do resolve the promise? I never used them before.

If I print, it's fine, but I need to use it outside:

 this.items=[];

    if(localforage.length()!=0){

        localforage.getItem('items').then(function (data) {
           this.items.=data;
        });
        //this.items=this.getData();
       //this.items.push(NewItems);
       console.log(this.items);
       //console.log(this.items);
    }

Can someone help me please?

Jacob H
  • 2,455
  • 1
  • 12
  • 29
  • 1
    You can't...... – epascarello May 21 '18 at 16:55
  • note that `this` isn't what you want it to be in the `then()` callback. See [How to access the correct `this` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – charlietfl May 21 '18 at 16:59

0 Answers0