【问题标题】:NGRX TypeError: Actions must have a type propertyNGRX TypeError:操作必须具有类型属性
【发布时间】:2021-04-20 05:00:07
【问题描述】:

我不明白如何避免此类错误NGRX TypeError: Actions must have a type property。请帮助找出问题所在。

我有两个动作,

export class UpdateWordListAction implements Action {
    static readonly TYPE: 'UPDATE_WORD_LIST';
    readonly type: "UPDATE_WORD_LIST";
    constructor() {};
}
export class WordListLoadedSuccessAction implements Action {
    readonly words: Word[];
    static readonly TYPE: 'WORD_LIST_LOADED_SUCCESS';
    readonly type: "WORD_LIST_LOADED_SUCCESS";
    constructor(words: Word[]) {};
}

一种效果,

@Injectable()
export class MyEffects {
 
     testEffect$ = createEffect(() => 
      this.actions$.pipe(
        ofType(UpdateWordListAction.TYPE),
        switchMap(() => this.wordService.getWordList()),
        map(words => new WordListLoadedSuccessAction(words)),
        catchError(() => EMPTY)));
 
  constructor(
    private actions$: Actions,
    private wordService: WordService
  ) {}
}

还有这样的客户

this.store.dispatch(new UpdateWordListAction());

【问题讨论】:

    标签: angular typescript rxjs ngrx


    【解决方案1】:

    您需要使用分配符号而不是冒号。试试这个:

        export class UpdateWordListAction implements Action {
           readonly type = "UPDATE_WORD_LIST";
           constructor() {};
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2016-01-23
      • 2023-03-24
      • 2017-05-21
      • 1970-01-01
      相关资源
      最近更新 更多