2017-01-22 47 views
0

同步功能我已經保存一些數據存儲在離子2.我可以創建在角2

import { Storage } from '@ionic/storage'; 
... ... ... 

constructer(public storage: Storage){} 

this.storage.set('usertype', usertype); 

現在我要創建從存儲中獲取數據。 程序邏輯必須是在存儲中使用創建的函數獲取數據後執行下一個函數。 如何創建Get函數或構建程序邏輯?

回答

1

看起來,如果你使用它返回的決議承諾Ionic2的nativeStorage模塊,所以使用例如,你可以做這樣做...

import { NativeStorage } from 'ionic-native'; 
... ... ... 

NativeStorage.setItem('usertype', usertype); 

.... 

NativeStorage.getItem('usertype') 
    .then(
    // everything here happens once you actually have the data 
    data => console.log(data), 
    error => console.error(error) 
);