my storage provider
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
@Injectable()
export class TestStorageProvider {
constructor(public storage: Storage) {
storage.ready().then(() => { });
}
save() {
this.storage.ready().then(() => {
this.storage.set('name', 'Max5');
});
}
load(): any {
this.storage.ready().then(() => {
this.storage.get('name').then((val) => {
console.log('Your name is', val);
});
});
}
}
page 1
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TestStorageProvider } from '../../providers/test-storage/test-storage';
@IonicPage()
@Component({
selector: 'page-summary',
templateUrl: 'summary.html',
})
export class Summary {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private testStorage: TestStorageProvider,
) {
}
ionViewDidLoad() { }
goToTest1() {
this.testStorage.save();
this.navCtrl.push('Test1Page');
}
}
page 2
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TestStorageProvider } from '../../providers/test-storage/test-storage';
@IonicPage()
@Component({
selector: 'page-test1',
templateUrl: 'test1.html',
})
export class Test1Page {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private testStorage: TestStorageProvider,
) {
}
ionViewDidLoad() {
this.testStorage.load();
}
}
Did i have to set timeout to wait before get value ?