Sorry, I am quite new to this and facing a bit of confusion.
So, I have a CalendarService which includes a method called getYear(id: string). The structure of my Year model is as follows:
export class Year {
id: string;
number: Number;
months: Month[];
weeks: Week[];
}
My objective is to retrieve data from Months[] such as name, numberOfDays, etc.
This is the implementation of my service:
@Injectable()
export class CalendarService {
endPoint: string;
private _calendarUrl = '/api/mycalendar';
months: Month[];
year: Date;
constructor(private http: HttpClient) {
}
getYear(id: string): Observable<Year> {
return this.http.get(this._calendarUrl + '?id=' + id)._catch(this.handleError);
}
getYears() {
return this.http.get(this._calendarUrl)
.map((res: Response) => res.json())
._catch(this.handleError);
}
getMonths(yearId: string) {
// Retrieve year data from database
const year = this.getYear(yearId);
// Accessing the months
this.months = year.
}
private handleError(error: any) {
const errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.log(errMsg);
return Observable.throw(error);
}
}