I am new to Angular and JS. Right now I am writing code to save data to Indexed db and I want to show number of records which are pending (in indexed db) on navigation bar, I am not able to get the total number of records saved to Indexed DB.
I am using the codes below to get the count, but it is only usable inside the arrow function/callback function. I have tried assigning it to global variable, but it returns null.
Here is the code, I want to utilize these methods and return the number of records which exists in the IDB.
private countIDBRecords() {
this.db.myTableName.toCollection().count( (count: string) => {
console.log(count + " records in total"); // this returns correct value, but i cannot use 'count' outside this function
this.totalRecords = count;
});
console.log(this.totalRecords); //return null
}