The 2017 Ionic Developer Survey Results are in!

Native Storage

Improve this doc

Native storage of variables in Android and iOS

Repo: https://github.com/TheCocoaProject/cordova-plugin-nativestorage

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-nativestorage
    $ npm install --save @ionic-native/native-storage
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { NativeStorage } from '@ionic-native/native-storage';

constructor(private nativeStorage: NativeStorage) { }

...

this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
  .then(
    () => console.log('Stored item!'),
    error => console.error('Error storing item', error)
  );

this.nativeStorage.getItem('myitem')
  .then(
    data => console.log(data),
    error => console.error(error)
  );

Instance Members

setItem(reference, value)

Stores a value

Param Type Details
reference string
value

Returns: Promise<any>

getItem(reference)

Gets a stored item

Param Type Details
reference string

Returns: Promise<any>

keys()

Retrieving all keys

Returns: Promise<any>

remove(reference)

Removes a single stored item

Param Type Details
reference string

Returns: Promise<any>

clear()

Removes all stored values.

Returns: Promise<any>

API

Native

General