Ngxs - 状态未定义

问题描述 投票:0回答:1

刚刚开始玩ngxs并且遇到了障碍。我不知道我做错了什么,但我得到'状态未定义'的错误。

行动:

const prefix = "[Tutorial]";

export class AddTutorial {
  static readonly type = `${prefix} Add Tutorial`;

  constructor(public payload: string) { }
}

州:

export class TutorialStateModel {
  tutorial: any[]
}

@State<TutorialStateModel>({
  name: 'tutorial',
  defaults: {
    tutorial: [],
  }
})
export class TutorialState {

  @Action(AddTutorial)
  addTutorial({ getState, patchState }: StateContext<TutorialStateModel>, { payload }: AddTutorial) {
    const state = getState();
    patchState({
      tutorial: [...state.tutorial, payload]
    });
  }

}

错误指向:const state = getState();

零件:

  ngOnInit() {
    this.store.dispatch(new AddTutorial('Redux'));
  }
angular state ngxs
1个回答
0
投票

这是我的缓存。我清除它现在它的工作原理。

© www.soinside.com 2019 - 2024. All rights reserved.