I have searched tirelessly for a solution, but none of them seem to work.
Every time I click on the edit button, it redirects me to edit-event page and shows me this error:
ERROR TypeError: Cannot read property 'categories' of undefined
ngOnInit() {
this.eventService
.getEventById(this.route.snapshot.params.id)
.subscribe((ev) => this.event = ev);
Once I subscribe, if I try console.log(this.event), it returns undefined.
However, .subscribe(console.log(ev));
returns an object.
I'm puzzled why this.event = ev
is not working, considering I have used it successfully in another component with no issues.
The service being called is as follows:
getEventById(id) {
return this.httpClient.get<EventsDto>(this.urlevent + '?id=' + id);
}
In edit-event.component.html, {{event.name}} gets printed. This baffles me because earlier we saw that this.event was undefined using:
.subscribe((ev) => this.event = ev)