2016-11-10 5 views
0

は私がionic Storageの使い方は?

data: any; 
token: string; 
phone:string; 
constructor(private http: Http, public storage: Storage) {} 


load() { 

this.storage.get('token').then((token) => { 
    this.token = token; 

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

    this.http.get('https://app.dev/clients.json?login='+this.phone+'&client_token='+this.token) 
      .map(res => res.json()) 
      .subscribe(data => { 
      // we've got back the raw data, now generate the core schedule data 
      // and save the data for later reference 
      this.data = data; 
      resolve(this.data); 
      }); 
     }); 

しかしthis.phone =電話をしようとした他に何も

this.storage.get('email').then((email) => { 
this.storage.get('token').then((token) => { 

    this.http.get('https://app.dev/clients.json?login='+email+'&client_token='+token) 
     .map(res => res.json()) 
     .subscribe(data => { 
     // we've got back the raw data, now generate the core schedule data 
     // and save the data for later reference 
     this.data = data; 
     resolve(this.data); 
     }); 
    }); 
}); 
}); 

を作業していないので、このまたは何最善の使用だように呼び出すために、この正常です。割り当てられていません

私はthis.storage.get( 'phone')と約束はしません。

+0

'this.phone = this.storage.get( 'phone');'を実行できますか? – Huiting

+0

それは約束です。 – flakerimi

+0

あなたはどのタイプのストレージを使用していますか? – Huiting

答えて

1

約束を返すので、コードの最初のスニペットが最も一般的な方法です。

古いバージョンのIonic 2(2.0.0-beta.4)を使用していますが、それでも.jsを使用していますので、お使いのバージョンで動作しているかどうかはわかりません。

import {LocalStorage} from 'ionic-angular'; 

constructor(...){ 
    this.local = new Storage(LocalStorage); 
    this.local.set("Key", "Key_Value"); 
} 

buttonClick(){ 
    this.key = localStorage.getItem('Key'); 
} 

これは現在、ローカルストレージを使用しています。あなたが約束に対処したくなければ、ちょうど提案。

+0

ええ、私はローカルストレージを持っていましたが、Ionicストレージはより多くのストレージエンジンをサポートしています。私は店舗からベストを得る方法についてもう少しお待ちしています。 – flakerimi

+0

私は純粋なjavascriptのlocalstorageと一緒に行かなければならなかった。 window.localstorage.getItem() – flakerimi

関連する問題