Hey there, I'm currently in the process of building an Ionic2 app with Firebase integration. Within my codebase, there's a provider known as Students-services where I've written a function to navigate through a node, retrieve values, and display them in an array. While everything seems to be functioning properly, I seem to be encountering an issue when attempting to return data to my page.ts file.
Below is the snippet from students services:
settropies(userId) {
let total = 0;
let result = [];
let query = this.userProfile.child(userId+'/exams/').orderByKey();
query.on("value",(snapshot) => {
snapshot.forEach((childSnapshot) => {
var key = childSnapshot.key;
var childData = childSnapshot.val();
total = total + childData.marks;
result.push(total);
this.marksarray = result;
});
this.marksarray = result;
console.log(this.marksarray[1]);
});
return this.marksarray;
}
I've called the function within my page.ts file:
console.log(this.studentservice.settropies(studentId));