I have an app and I'm getting some Observable Objects through a data service. This is my code:
this.currentUser$ = dataService.getUser(authService.id);
this.currentUser$.subscribe(user => {
this.currentUser = user;
this.classes = dataService.getClasses(this.currentUser.school, this.currentGroup);
this.activities = dataService.getActivities(this.currentUser.school, this.currentGroup, this.currentClassId);
});
This works when the page first loads, but there's a button that should update the Class ID so the page display the activities from the previous class, but I can't find a way to update the observable so I can get the data from another class.
In the button's click event, use event binding to bind to a method of the component. In that method, call the getActivities service method. So something like this:
getActivitiesForClass() {
this.activities = this.dataService.getActivities(this.currentUser.school, this.currentGroup, this.currentClassId);
}