Reputation: 101
I'm trying to add a row to a locally stored array
Here I leave a photo with what I currently have
I want to add a row to array "Encuestas" with the following code
public Encuestas :any[];
this.Encuestas= [
{
id:"3",
mysqlid:"1",
nombre:"Encuesta de Cigarrillos",
img:"albums",
descripcion:"Encuesta Aplicable"
}
]
constructor(public http: Http,public local:Storage) {}
PostEncuestas(){
this.local.ready().then(()=>{
this.local.set('encuestas',this.Encuestas);
})
}
when I call the function. the array "encuestas" is replaced entirely by the sent array
is there a push method on ionic3?
Upvotes: 2
Views: 39
Reputation: 4013
You should first try to load the array with:
this.local.get('encuestas').then((data) => this.Encuestas = data);
Apply the updates to the Encuestas
array and then do the PostEncuestas()
To push the data use:
this.Encuestas.push({
id:"3",
mysqlid:"1",
nombre:"Encuesta de Cigarrillos",
img:"albums",
descripcion:"Encuesta Aplicable"
});
Upvotes: 1