Как исправить ошибку «Не удается прочитать свойство forEach of undefined» в Angular - PullRequest
0 голосов
/ 02 января 2019

У меня есть ошибка, но я не знаю, что еще нужно сделать, чтобы ее исправить.Ниже приведен мой код и ошибка:

courses: any[] = [];

ngOnInit() {
    this.locale = this.localeService.currentLocale();
    this.user = this.authService.getCurrentUser();
    this.userService.getCoursesInProgress(this.user.id).subscribe(courses => {
        this.coursesInProgress = [];
        courses.forEach(n => {
            const courseObj: Course = new Course(n);
            this.coursesInProgress.push(courseObj);
        });
    });
    this.userService.getCoursesFinished(this.user.id).subscribe(courses => {
        this.coursesFinished = [];
        courses.forEach(n => {
            const courseObj: Course = new Course(n);
            this.coursesFinished.push(courseObj);
        });
    });
}

TypeError · Невозможно прочитать свойство 'forEach' из неопределенного

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...