【发布时间】:2019-05-22 22:23:50
【问题描述】:
我是第一次使用 switchMap。它告诉我要返回“某物”,但是当我返回时它不起作用。
@Effect()
subData$ = this.actions$.pipe(
ofType(ActionTypes.SEARCH_SUB_DATA),
map(action => action['payload']),
switchMap(payload => { //Payload gets highlighted in red
const repos = this.githubSearch.getRepos(payload);
const followers = this.githubSearch.getFollowers(payload);
const starred = this.githubSearch.getStarred(payload);
return forkJoin([repos, followers, starred]).subscribe(results => {
this.store.dispatch(
new UserActions.SuccessSubData({
user: payload,
repos: results[0],
followers: results[1],
starred: results[2]
})
);
return of(results);
});
})
);
'(payload: never) => Subscription' 类型的参数不可赋值 到类型参数'(值:从不,索引:数字)=> 可观察输入'。类型“订阅”不可分配给类型 'ObservableInput'。
根据提供的答案进行更新
@Effect()
subData$ = this.actions$.pipe(
ofType(ActionTypes.SEARCH_SUB_DATA),
map(action => action['payload']),
switchMap(payload => {
return forkJoin(
this.githubSearch.getRepos(payload),
this.githubSearch.getFollowers(payload)
);
}).subscribe(results => {
this.store.dispatch(
new UserActions.SuccessSubData({
user: payload,
repos: results[0],
followers: results[1]
})
);
})
);
这是显示错误的图片
【问题讨论】:
标签: angular rxjs observable