0

我是 Ngrx 的新手,我们在实施中遇到了困难,需要一些帮助

架构:当用户通过身份验证时,我们正在尝试填充存储,然后尝试重定向。

期望:效果应该被称为异步,在 ui 中我们必须做重定向

问题:重定向到主页仅在 ngrx/effect api 调用完成后才会发生。

 this.userService.authenticateUser(this.userId.toUpperCase(), this.password, (user) => {
            this.authenticatedUser = user;                
            //Call the ngrx dispatchMethod to fill the store
            this.router.navigateByUrl("/home");
             this.ngrxGetModule_data();

 async  ngrxGetModule_data() {
        this.store.dispatch({ type: Affaire_Action.Affaire_Addstore_Login });
        //this.store.dispatch({ type: Affaire_Action.Initial_Store });
    }



@Effect()
    updateAffaireStore$: Observable<Action> = this.actions$
        .ofType(Affaire_Action.Affaire_Addstore_Login)
        .map<Action, string>(toPayload)
        .switchMap(res => this.affaireService.getAffairesSearchSuggetions('')
            //.delay(10000)
            .map(res => (
                {
                    type: Affaire_Action.Affaire_on_Success, payload: ({ "parameter": SearchSuggestion, "data": res })

                }
            )))
        .catch(error => Observable.of({ type: Affaire_Action.Affaire_on_Failure, payload: null }))
4

1 回答 1

1

您实际上在尝试this.userService.authenticateUser什么?似乎您正在尝试调用该函数,但您的操作方式是错误的。返回类型是什么?!!!可观察或承诺。

建议:您应该在效果上调用服务并从效果中调度操作。你也可以使用this.router.navigateByUrl("/home");你的效果。

于 2021-05-29T16:26:21.797 回答