Angular 2 - forkJoin 无法绑定正确的 lass
Angular 2 - forkJoin can't bind the correct lass
我正在尝试同时进行多个 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[]>
任何人都可以帮助我了解问题所在?
这样试试:
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;
);
我正在尝试同时进行多个 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[]>
任何人都可以帮助我了解问题所在?
这样试试:
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;
);