Im having a problem with what I believe is a javascript promise issue. Although this is an angular6 app, I think that anyone with JavaScript expertise could probably help me out here.
Im calling a simple js function in a separate js file from my angular component. The simple js function grabs a list of connection strings from a local database and tries to return said list. I set an alert as you can see in my code so i know im getting the information that i need.
The problem is that by the time It gets back to the top calling method (line 4), its empty! Its as if its returning a promise instead of the actual array.. How can I get the actual value back?
Thanks in advance.
//MY ANGULAR6 COMPONENT
public getLocal() {
this.Connections = [];
this.Connections = fetchFromLocalDatabase();
}
//MY IMPORTED JS FILE
fetchFromLocalDatabase() {
let myArray = [];
idb.open('InfoRail', 1).then(function (db) {
var tx = db.transaction(['ConnectionStrings'], 'readonly');
var store = tx.objectStore('ConnectionStrings');
return store.getAll();
}).then(function (items) {
myArray = items;
alert('show me ' + myArray[0].DatabaseName);
});
return myArray;
}