How to pass data from one screen to another with Native LocalStorage and Ionic 3?

0

I would like to know how to pass data from one item to a form in another view using Native LocalStorage from Ionic 3.

I created a provider as shown below:

import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';

/*
  Generated class for the MovimentosProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class MovimentosProvider {

  lista:any[];
  chave:string = "movimentos";

  constructor(private storage: Storage) {
    this.storage.ready().then(()=>{
      this.storage.get(this.chave).then((registos) =>{
        if(registos){
          this.lista = registos;
        }else{
          this.lista = [];
        }
      });      
    });    
  }

  listar(){
    return this.lista;
  }

  adicionar(registro:any){    
    this.storage.ready().then(()=>{
      this.lista.push(registro);
      this.storage.set(this.chave, this.lista); 
    }); 
  }

}

And I have a button editarMovimento but I want to pass what I captured from the listing to the form and can edit it.

editarMovimento(movimento:IMovimento){    
    this.movimento = movimento;

  }

How can I do this?

    
asked by anonymous 29.08.2018 / 20:56

1 answer

0

I do not know if I understood your question exactly.

Inside the button you pass as parameter the key you want to edit, the one you used in storage.set

storage.get(SUA CHAVE AQUI).then((val) => {
    console.log(val);
  });

Remembering that return is always a string, so if you saved an object you would need to transform the string into an object.

    
11.09.2018 / 16:13