NGRX TypeError: Actions must have a type property
NGRX TypeError: Actions must have a type property
我不明白如何避免这种错误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());
您需要使用赋值符号而不是冒号。试试这个:
export class UpdateWordListAction implements Action {
readonly type = "UPDATE_WORD_LIST";
constructor() {};
}
我不明白如何避免这种错误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());
您需要使用赋值符号而不是冒号。试试这个:
export class UpdateWordListAction implements Action {
readonly type = "UPDATE_WORD_LIST";
constructor() {};
}