0
votes

I created an Ionic application with tabs and Ionics Storage for data storage.

In a tab (tab1), I have data and in another tab (tab2), I want to modify and set it in storage, but when I return to tab1, there is no change, only when I refresh.

The constructor is called only in the creation.

How can I fix that?

This is my ts 1tab

export class SaldoPage {
saldoAttuale:number;
controllo1Accesso:boolean= this.controllo();

constructor(public navCtrl: NavController, private storage: Storage,public zone: 
NgZone) {
 this.storage.get('saldoAttuale').then((val) => {
  this.saldoAttuale = val;
  console.log('entro');
});
}


 controllo(){
 this.storage.get('1accesso').then((val) => {
  if(val == null){
    val = true
  }
  else {
    val = false
   }
  this.controllo1Accesso = val;
});
return this.controllo1Accesso;
}

conrollando1Accesso(){
this.storage.get('1accesso').then((val) => {
  this.controllo1Accesso = val;
});
}
}    
1
Show us the relevant code of tab1. - Jeroen Heier
Create a provider that handles retreiving/storing the data in storage, and store your data there during runtime. Inject the provider in both tabs, you'll have one instance of that data in both tabs. - JoeriShoeby
You can use ionic specific life cycle events. Like ionViewDidEnter, or ionViewDIdLoad etc. - Jithin

1 Answers

0
votes

Try moving your constructor code to ngOnInit or ngAfterViewInit

ngOnInit(){
 this.storage.get('saldoAttuale').then((val) => {
  this.saldoAttuale = val;
  console.log('entro');
});
}