在两个动作Angular2 + ngxs之间切换

时间:2018-07-06 18:22:24

标签: angular ngxs

我在打开和关闭搜索栏的状态下有两个动作,如何在它们之间进行切换。

`@Action(OpenSearchBar)
    OpenSearchBar({ patchState }: StateContext<GalleryStateModel>) {
        patchState({ isSearchBarOpen: true });
    }
    @Action(CloseSearchBar)
    CloseSearchBar({ patchState }: StateContext<GalleryStateModel>) {
        patchState({ isSearchBarOpen: false });
    }

`

1 个答案:

答案 0 :(得分:0)

@Action( ToggleSearchInput )
toggleSearchInput(ctx: StateContext<GalleryStateModel>) {
    const state = ctx.getState();
    ctx.setState(
        produce(state, draft => {
            draft.isSearchBarOpen = !state.isSearchBarOpen;
        })
    );
}`