Angular 在一个NgEffects中链接两个服务器调用
我正在使用ngrx,我不知道如何在一个ngEffect中链接两个服务器调用。你知道怎么做吗?我需要你的帮助Angular 在一个NgEffects中链接两个服务器调用,angular,ngrx,ngrx-effects,ngrx-store,Angular,Ngrx,Ngrx Effects,Ngrx Store,我正在使用ngrx,我不知道如何在一个ngEffect中链接两个服务器调用。你知道怎么做吗?我需要你的帮助 @Effect() patternsSources$ :Observable<Action> = this.actions$ .ofType(GET_PATTERN_SOURCE_ACTION) .switchMap(action => this.service.getPatternSource(action.payload)) .ma
@Effect() patternsSources$ :Observable<Action> = this.actions$
.ofType(GET_PATTERN_SOURCE_ACTION)
.switchMap(action => this.service.getPatternSource(action.payload))
.map((patternsData:Sources) => new GetPatternsSourcesResponse(patternsData))
@Effect() patternsList$ :Observable<Action> = this.actions$
.ofType(GET_PATTERN_LIST_ACTION)
.switchMap(action => this.service.getPatternList(action.payload))
.map((data) => new GetPatternsListResponse(data));
以及派遣行动
export class AppComponent {
constructor(public store:Store<ApplicationState>) {
this.store.dispatch(new GetPatternsSourcesAction('/sources'));
this.store.dispatch(new GetPatternsListAction('/rules'));
}
}
这听起来不像是调度问题 似乎你的方法是:
handleGetPatternSourcesResponse(state,action as GetPatternsSourcesResponse);
及
在该州的同一地区运作。我认为“我在减速机中获得相同的数据”这句话没有其他意义。
因此,在状态中应该有两个不同的位置:patternslist和patternSources,每个完整的操作都应该在reducer中相应地处理。
这样,您以后就可以进行存储。选择(您需要的部件)。为什么要连锁它们?在我看来,它们是两个独立的动作,每个动作都有自己的效果。代码应该可以正常工作。因为我使用了一个reducer,并且丢失了第一个调用数据,我不知道。我在reducer中看到的只是第一个数据,即使有一个reducer,也有两个动作(getPatternsSourceResponse和getPatternsLisResponseAction)。在每种情况下,它们在减速器中应该有不同的类型和句柄。也许可以使用动作和减速器的定义更新问题,以便更清楚。完成。我添加了调度操作和reducer函数没有办法链接两个服务器调用?当然有:Observable.zip(request1observablesolved,request2observablesolved,(first,second)=>first&&second)。其中request1ObservableResolved和request2ObservableResolved是布尔值,表示您的请求已完成(来自存储区的标志)。
export class GetPatternsSourcesAction implements Action {
type = GET_PATTERN_SOURCE_ACTION
constructor(public payload?:string) {}
}
export class GetPatternsSourcesResponse implements Action {
type = GET_PATTERN_SOURCE_RESPONSE_ACTION;
constructor(public payload?:Sources) {}
}
export class GetPatternsListAction implements Action {
type: string = GET_PATTERN_LIST_ACTION;
constructor(public payload?:string) {}
}
export class GetPatternsListResponse implements Action {
type: string = GET_PATTERN_LIST_RESPONSE_ACTION;
constructor(public payload?:PatternList) {}
}
handleGetPatternSourcesResponse(state,action as GetPatternsSourcesResponse);
handleGetPatternListResponse(state,action as GetPatternsListResponse);