I am currently developing a mobile app using ionic 2. i have this set of code that need to retrieve data from sqlite and then further take this value for some other functionality. See below
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}`);
The value of cVersion is null since I am guessing that the call to sqlite is an asynchronous one. One quick fix which I think would work will be to include all the next logic in the database call function getcVersion but is there any solution like waiting for the database call to end and then continue executing after?
Thanks, Ashley
.then()function. You can shift all the code you have which needscVersion, in it's.then()part. Also, make sure to take necessary actions in.catch().