【发布时间】: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