Angular 2 Observable.forkJoin结果

时间:2017-07-28 08:54:29

标签: angular rxjs observable

我的组件中有以下代码:

public user: User;
public roles: Role[];
public organizations: Organization[];

public ngOnInit() {
  this.user$ = this.userService.getUser(1).share();
  this.roles$ = this.roleService.getRoles().share();
  this.organizations$ = this.organizationService.getOrganizations().share();

  Observable.forkJoin([this.user$, this.roles$, this.organizations$]).subscribe(data => {      
    this.user = data[0];
    this.roles = data[1];
    this.organizations = data[2];
  });
}

我认为这应该有效,但我在IDEA中遇到错误,它甚至无法编译,我现在已经坚持了一段时间,有人可以帮忙吗?

enter image description here

服务方法如下所示:

public getRoles(): Observable<Role[]> {
        return this.http.get(this.API_URL).map(res => res.json());
 }

0 个答案:

没有答案