Using LocalStorage ionic 2


#1

i have two text fields and have to take data from both of them and store it using LocalStorage
so here is the code i’ve implemented but its not working can you tell me to solve it.

in page1.html

<ion-input [(ngModel)]="hour" type="number"  ></ion-input>

 <ion-input [(ngModel)]="min" type="number" ></ion-input>

<button clear (click)="setTime(hours,min)" item-right >settime</button>

in pag1.ts

export class Page1 {

   public hour;
   public min;
   public local:Storage; 

  constructor(public nav: NavController, translate:TranslateService) {}
 
 
 setTime(hour, min){
 
   if(hour<24 && hour>0 && min>0 && min<61){
       this.local.set('hour',JSON.stringify(hour));
       this.local.set('min',JSON.stringify(min));
   }
   else{
     console.log("OUTOF LIMIT TIME EXCEPTION the values are "+hour+min);
   }
 }
 
  }

on console log it is showing
[Object Object ] at the end

and please also tell about get from localStorage.
Thanks in advance :slight_smile:


#2
constructor(public nav: NavController, translate:TranslateService) {
  this.local = new Storage(LocalStorage);
}

#3

oh thanks :slight_smile: …and one morething… in html it was setTime(hour,min)