Angular 从一个效果中分派多个操作

Angular 从一个效果中分派多个操作,angular,ngrx,ngrx-store,ngrx-effects,Angular,Ngrx,Ngrx Store,Ngrx Effects,嗨,我想在“loadFullService$”效果中分派我的新操作“LoadConfig” 怎么办 @Effect() loadFullService$: Observable<Action> = this.actions$ .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE) .switchMap(action => { ret

嗨,我想在“loadFullService$”效果中分派我的新操作“LoadConfig”

怎么办

    @Effect()
loadFullService$: Observable<Action> = this.actions$
    .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
    .switchMap(action => {
        return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
    })
    ;

@Effect()
loadConfig$: Observable<Action> = this.actions$
    .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
    .switchMap(action => {
        console.log("action config", action);
        return this.apiService
            .loadConfig(action.id, action.name)
            .map((config: Configuration) => new servicesActions.LoadConfigSuccess(config))
            .catch(error => of(new servicesActions.LoadConfigFailure(error)));
    });
@Effect()
loadFullService$:Observable=this.actions$
.类型(服务操作.加载完整服务)
.switchMap(操作=>{
退回此服务
.loadFullService(操作.有效负载)
.map((服务:服务)=>新服务操作.LoadFullServiceSuccess(服务))
.catch(错误=>of(新服务选项.LoadFailureAction(错误));
})
;
@效果()
loadConfig$:Observable=this.actions$
.of类型(servicesActions.LOAD\u CONFIG)
.switchMap(操作=>{
log(“操作配置”,操作);
退回此服务
.loadConfig(action.id,action.name)
.map((配置:配置)=>newservicesactions.LoadConfigSuccess(配置))
.catch(错误=>of(新服务选项.LoadConfigFailure(错误));
});

在构造函数中导入存储服务

constructor(
  private store: Store<StoreType>,
)

效果不是只包含一个元素的函数。它们是流转换,您可以在这里使用RxJS的所有功能。例如,要获得您在标题中要求的内容:

@Effect()
loadConfig$: Observable<Action> = this.actions$
    .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
    .switchMap(action => Observable.of(
        new OtherAction(),
        new OtherAction2(),
    );
@Effect()
loadConfig$:Observable=this.actions$
.of类型(servicesActions.LOAD\u CONFIG)
.switchMap(动作=>可观察的(
新建其他操作(),
新的OtherAction2(),
);

注意:这与安德烈答案中的第三个版本非常相似。

我尝试过,但效果如何?执行a.do(this.store.dispatch(new servicesActions.LoadConfig(action.id,action.name))?Thx u!最后一个问题我需要“name”,它是“LoadFullService”的返回值动作,我可以取回它吗?
action.payload.name
来自LoadFullService。或者你是说LoadFullServiceSuccess?如果你使用类,它可能位于
action.name
。我是说LoadFullServiceSuccess