Delete all local storage


#1

hey guys
if i want to create a button that delete all local storage from all page in my app i use ionic 2 typescript :slight_smile:

Regards


#2

According to the ionic2 API, the method you need is clear().

http://ionicframework.com/docs/v2/api/platform/storage/LocalStorage/

So your code might look like this:

import {Component} from '@angular/core';
import {Storage, LocalStorage} from 'ionic-angular';
@Component({
  template: `<ion-content></ion-content>`
});
export class MyClass{
 constructor(){
   this.local = new Storage(LocalStorage);
   this.local.set('didTutorial', 'true');
 }

function resetLocalStorage(){
  this.local.clear();
}

}


#3

hi @Gatewayapp

You need to call the clear() method of your local storage.
e.g localStorage.clear();
OR you can use $localStorage.$reset();
it will delete all your data from localStorage.