Keep the cache of a JSON query on IONIC 3

0

Hello, I have an App that consumes JSON and lists the data, so far so good. My difficulty is in keeping this data for offline access. I want to consult after you're offline.

Q: I have been testing with Service Worker, it works perfectly but in the browser, when I put it in the app, it does not work, it does not keep the cache.

I would like some links or some success story there.

Thanks in advance!

    
asked by anonymous 09.04.2018 / 00:38

1 answer

0

Using Ionic Storage :

...

import { Storage } from '@ionic/storage';

@NgModule({

   ...

   providers: [
     Storage
   ]
 })


export class AppModule {}

...


import { Storage } from '@ionic/storage';

export class MyApp {
    constructor(storage: Storage) {

    // set        key   value
    storage.set('myKey', 'myVal');

    // get value 
    storage.get('myKey').then((val) => {

      //CASO HAJA VALOR, NAO REALIZAR CONSULTA EXTERNA
      if(val)
      //...

    })
 }
}
    
09.04.2018 / 15:37