2017-03-20 9 views
0

私は現在ionic 2を使用してモバイルアプリケーションを開発中です。このコードセットはsqliteからデータを取得し、さらにこの値を他の機能に使用する必要があります。私はsqliteのへの呼び出しが非同期一つであることを推測していますので、cVersionの値がnullであるハイブリッドアプリケーションは、sqliteとangular2を使用してデータベース呼び出しを行います

this.credentials = _credentials; 
 
let username = _credentials.username; 
 
let password = _credentials.password; 
 
let cVersion; 
 
**this.localDbService.getcVersion().then((data) => { 
 
    cVersion = data; 
 
});** 
 
console.log(cVersion); 
 
//build http header and make http call to servlet to retrieve details 
 
let myHeaders: Headers = new Headers(); 
 
let digest = btoa(`${username}:${password}`);

の下を参照してください。データベースコール関数getcVersionに次のすべてのロジックを含めることになりますが、データベースコールが終了するのを待ってから実行を続けるような解決策はありますか?

おかげで、 アシュリー

+0

私はそれが '.then()'関数の全目的だと思います。あなたは 'cVersion'を必要とする全てのコードを' .then() '部分にシフトすることができます。また、 '.catch()'で必要な処理を行ってください。 –

答えて

0
Replace this 

this.credentials = _credentials; 
let username = _credentials.username; 
let password = _credentials.password; 
let cVersion; 

this.localDbService.getcVersion() 
.then((data) => { 

cVersion = data; 

console.log(cVersion); 

//build http header and make http call to servlet to retrieve details 
let myHeaders: Headers = new Headers(); 
let digest = btoa(`${username}:${password}`); 

}); 

乾杯!

関連する問題