I am working on a project in which I have to get students enrolled courses and courses list.
getting course
this.courses = <Array<Course>>[];
this.coursesService.getCourses().subscribe((response: Array<Course>) => {
this.courses = response;
console.log(this.courses);
});
getting Students enrolled course
this.id = this.router.snapshot.paramMap.get('id');
this.studentService.getStudentsById(this.id).subscribe((response: Student) => {
this.student = response;
console.log(this.student);
});
my code for getting avail
this.courses.forEach(function(item, i, object) {
this.student.enrollments.forEach(function(enrollments, j , objectb) {
if (item === enrollments) {
object.splice(i, 1);
}
});
});
So when my page load. it didnt splice/remove the item in the courses which he is currently enrolled.I think the forEach function executes before it has values. is this about the subsribe? or im just doing it all wrong