微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

UpdateFormValue 在更改表单值之前调度

如何解决UpdateFormValue 在更改表单值之前调度

UpdateFormValue 操作是在更改表单值之前调度的,因此当 UpdateFormValue 完成时无法执行任何操作,因为第一个操作完成得比预期早。请寻求您的帮助。

ngOnInit(): void {
    this.store.dispatch(new ShowLoading());
    this.actions$.pipe(
        ofActionSuccessful(UpdateFormValue),take(1)
    ).subscribe(() => {
        this.store.dispatch(new HideLoading());
    });

    this.activatedRoute.params.subscribe(
        (params: Params) => {
            // Fetch by id.
            if (params?.id) {
                this.store.dispatch(new FetchById(params.id));
            }
        }
    );
}

@Action(FetchById)
fetchById(context: StateContext<ArticlesstateModel>,action: FetchById) {
    // Get the data.
    this.articleService.fetchArticleById(action.id).subscribe((response: ApiResponse) => {
        if (response.isValid() && response.isSuccess()) {
            const article: Article = this.getModelData(response).pop();

            context.patchState({current: article});

            context.dispatch(
                new UpdateFormValue({
                        path: 'articles.form',value: article
                    }
                )
            );
        }
    });
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。