我试图一起做多个ajax调用。 我无法弄清楚这些线路有什么问题。似乎订阅函数的第二个输入被处理为Group []而不是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[]>
任何人都可以帮我理解这是什么问题?
答案 0 :(得分:0)
试试这样:
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;
);