angular-localForage icon indicating copy to clipboard operation
angular-localForage copied to clipboard

Newb Q: How do I know if the instance wasn't created before?

Open GianlucaBobbio opened this issue 8 years ago • 2 comments

Im on Ionic, I need a DB to work on, with and without connection. My Q is, I need 2 instances of localForage, so how do I put in angular.run() that? I tried

if(!$localForage.instance('WorkOrders')){
        $localForage.createInstance({
            name: 'WorkOrders'
        });
    }

    if(!$localForage.instance('Inspections')){
        $localForage.createInstance({
            name: 'Inspections'
        });
    }

But it's not working (its first time so localForage.instance('Inspections') doesn't exist, but crush instead returning null)

GianlucaBobbio avatar Feb 26 '16 21:02 GianlucaBobbio

I was having the same problem and i solve it using "try" and "catch"

 try {
      this.articlesInstance=$localForage.instance('articles');
    }
    catch(err) {
      this.articlesInstance = $localForage.createInstance({
        name: 'articles'
      });
    }

I hope it helps you

maiskovich avatar Aug 04 '16 03:08 maiskovich

Thanks, good idea. I finally did on another way (old project, cant remember)

GianlucaBobbio avatar Aug 04 '16 15:08 GianlucaBobbio