I have an object method below that takes an argument of another object 'backend'. It uses a method from the backend object 'fetchClassrooms$()' which returns an observable. The issue I'm having is that when I try and call the function 'buildDOM' from the observable's execution I get the error "cannot read property 'buildDOM' of undefined". I think it's a scoping issue where the observable's execution scope is different from the 'fetchClassrooms' scope. If so, is there a better way of calling a function from within an observable's execution that comes from a different object?
fetchClassrooms (backend) {
function buildDOM (data) {
for(let classroom in data){
for (let student in data[classroom]){
let time = data[classroom][student];
this.buildDOM(classroom, student, time);
}
}
this.classroomSelected = Object.keys(data)[0];
};
backend.fetchClassrooms$()
.subscribe(
dataSnapshot => {
this.classrooms = dataSnapshot.val();
buildDOM(this.classrooms);
},
err => console.log(err),
() => console.log('complete')
);
},