Angular 角度2数据服务更新可观测

Angular 角度2数据服务更新可观测,angular,angular2-services,Angular,Angular2 Services,我有一个应用程序,我通过数据服务获取一些可观察的对象。 这是我的代码: this.currentUser$=dataService.getUser(authService.id); 此.currentUser$.subscribe(用户=>{ this.currentUser=用户; this.classes=dataService.getClasses(this.currentUser.school,this.currentGroup); this.activities=dataServic

我有一个应用程序,我通过数据服务获取一些可观察的对象。 这是我的代码:

this.currentUser$=dataService.getUser(authService.id);
此.currentUser$.subscribe(用户=>{
this.currentUser=用户;
this.classes=dataService.getClasses(this.currentUser.school,this.currentGroup);
this.activities=dataService.getActivities(this.currentUser.school、this.currentGroup、this.currentClassId);

});在按钮的单击事件中,使用事件绑定绑定到组件的方法。在该方法中,调用getActivities服务方法。比如说:

getActivitiesForClass() {
    this.activities = this.dataService.getActivities(this.currentUser.school, this.currentGroup, this.currentClassId);
}

您可以使用observer更新可观察对象。这可能是唯一的方法。我以前试过,但没有成功,我用“this.activities=this.dataService.getActivities(this.currentUser.school,this.currentGroup,this.currentClassId);”再次尝试,现在成功了。非常感谢。