2017-09-24 45 views
0

我從存儲在離子2.通行證存儲值反對離子2

 this.storage.get('name').then((nama) => { 
      this.name = nama 
     }); 

獲得價值,我想傳遞數據「this.name」的對象,但是當我運行的應用程序,它不是返回任何

this.userData = { 
     id: '0404040404', 
     nama: this.name, 
     no_hp: '082211590346', 
     email: '[email protected]' 
    } 

這裏我完整的代碼

name:any 
userData: {id: string, nama: string, no_hp: string, email: string} 

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

     this.storage.get('name').then((nama) => { 
      this.name = nama 
     }); 

    this.userData = { 
     id: '0404040404', 
     nama: this.name, 
     no_hp: '082211590346', 
     email: '[email protected]' 
    } 
} 

回答

0

用戶數據應在承諾的結果啓動:

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

     this.storage.get('name').then((nama) => { 
      this.name = nama 
      this.userData = { 
       id: '0404040404', 
       nama: nama, 
       no_hp: '082211590346', 
       email: '[email protected]' 
      } 
     }); 


}