Storage return undefined value when calling from another page


hi all
i have strange issue
i using (( Storage )) as on
but when i set storage from page and return value from another page
on first time that i calling this value i get undefine value but other times it give the correct value

why ??
can some one help me please


Please show us the code you’re using on two components and how they interact with each other. Hard to tell what’s going on without seeing any code.


hi luukschoen,
on first page i put this on button (click)
setValue(){‘key’, ‘hhhhh’)

second page

import { Component, OnInit } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import {Storage} from ‘@ionic/storage’;

selector: ‘page-about’,
templateUrl: ‘about.html’
export class AboutPage implements OnInit {
private val1: string;
private val2: string;

constructor(public navCtrl: NavController,
private storage: Storage) {}

ngOnInit() {‘key’).then((value) => {
console.log('Inside '+value);
this.val1 = value;

console.log('Outside ' + this.val1);


/*‘key’).then((value) => {
this.val2 = value;



thanks , i solve the problem

the problem that i must put every thing inside (( then ))‘key’).then((value) => {

    (( put every thing here )) 

thanks again