Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appropriate Local Storage for Ionic 3

I am reading about Local Storage and I am quite confused. As I see there are two options:

Native Storage , import { NativeStorage } Ionic Storage, import { IonicStorageModule } My app is developed with Ionic 3 and I am trying to save an array of object localy after retrieve it from Parse Server.

With Ionic 1 I stored the objects array like this:

setUsers (users){
    window.localStorage.users_data = JSON.stringify(users);
}
getUsers(){
   return JSON.parse(window.localStorage.users_data || '[]');
}

So now, what is the best option to save my data and stringfy them and parse them?

Native storage or Ionic Storage?

Thank you a lot

like image 857
giorgionasis Avatar asked Oct 08 '17 09:10

giorgionasis


People also ask

Can I use localStorage in ionic?

Ionic Storage abstracts all available mechansims for data storage such as native Cordova SQLite and browser storage APIs like IndexedDB, WebSQL or localStorage.

What is the limit of local storage in ionic?

Ionic Local Storage uses the local storage system of browser for key/value pairs storing. The limit of Local Storage is only 5MB.

Is ionic storage safe?

On-device data encryption: Sensitive data is protected and kept securely on the device with 256-bit AES full database encryption. The powerful operating system-level security follows Apple and Google's best practices.

Does ionic storage work in web?

Ionic Storage is useful for building single code-base apps on iOS, Android, and the Web, while automatically using the best storage engine available on the platform the app is running on.


1 Answers

You can easily use Ionic storage module here. You just need to install SQLite plugin. Details are in the above doc. Then you can use it natively on iOS and Android too without any issue.

Usage:

 // set a key/value
  storage.set('name', 'Max');

  // Or to get a key/value pair
  storage.get('age').then((val) => {
    console.log('Your age is', val);
  });
like image 157
Sampath Avatar answered Sep 28 '22 16:09

Sampath