Angular 2-forkJoin无法绑定正确的lass [英] Angular 2 - forkJoin can't bind the correct lass

查看:98
本文介绍了Angular 2-forkJoin无法绑定正确的lass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一起进行多个ajax调用. 我不知道这些行出了什么问题.好像订阅功能的第二个输入被处理为Group []而不是Authorization []

I'm trying to do multiple ajax calls together. I can't figure out what is wrong with these lines. Seems like the second input of the subscribe function is processed as Group[] instead of Authorization[]

 Observable.forkJoin(
            [this.userService.getAllGroups(),this.userService.getAllAuthorizations()]
        )
        .subscribe(
            ([groups,authorizations]) => {
                this.groups = groups;
                this.authorizations = authorizations; //error: Type 'Group[]' is not assignable to type 'Authorization[]'
                this.loaderService.hideLoader();
            },
            (err)=>{
                this.loaderService.hideLoader();
            }
        );

接口是:

(method) UserService.getAllGroups(): Observable<Group[]>
(method) UserService.getAllAuthorizations(): Observable<Authorization[]>

任何人都可以帮助我了解问题所在吗?

Anyone can help me understand what the is problem?

推荐答案

尝试如下:

Observable.forkJoin<Group[], Authorization[]>(
         this.userService.getAllGroups(),
         this.userService.getAllAuthorizations()
      ).subscribe(results => {
         this.groups = results[0];
         this.authorizations = results[1];
      );

Observable.forkJoin<Group[], Authorization[]>(
         this.userService.getAllGroups(),
         this.userService.getAllAuthorizations()
      ).subscribe((groups, authorizations) => {
         this.groups = groups;
         this.authorizations = authorizations;
      );

这篇关于Angular 2-forkJoin无法绑定正确的lass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆