Hi i'm developing an ionic2 app with firebase.So here I have a provider called Students-services.I worte a function in the service for go through a node and get values.after that it will showing in an array.all are working.But i can't return data to my page.ts file. it shows undifined.But if i put it in the console i can see the values what i need. Can anyone please help me.
here is my function in 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 Called the function in my page.ts file
console.log(this.studentservice.settropies(studentId));