angular – NGRX:TypeError:Actions必须具有type属性
发布时间:2020-12-17 17:47:13 所属栏目:安全 来源:网络整理
导读:作为ngrx的新手,我面临一个例外,不知道为什么…… 我试图调度一个动作并在一个效果中处理它,但我不断收到错误:TypeError:Actions必须有一个type属性 操作: export const TEST_ACTION = 'test_action';export class TryTest implements Action { readonly
|
作为ngrx的新手,我面临一个例外,不知道为什么……
我试图调度一个动作并在一个效果中处理它,但我不断收到错误:TypeError:Actions必须有一个type属性 操作: export const TEST_ACTION = 'test_action';
export class TryTest implements Action {
readonly type = TEST_ACTION;
constructor(public playload: any) {
}
}
export type MyActions = TryTest;
功效: import * as MyActions from "./myactions.actions";
@Injectable()
export class MyEffects {
@Effect()
testEffect = this.actions$
.ofType(MyActions.TEST_ACTION)
.map((action: MyActions.TryTest) => {
return 'something'
});
constructor(private actions$: Actions) {}
}
零件: this.store.dispatch(new MyActions.TryTest({ name: 'test' }));
我在用: 效果:4.0.5和存储:4.0.3 解决方法
因为效果必须在最后返回一个动作.
所以你有两个选择: >返回一个{type:string}对象 从“./myactions.actions”导入*作为MyActions; @Injectable()
export class MyEffects {
@Effect()
testEffect = this.actions$
.ofType(MyActions.TEST_ACTION)
.map((action: MyActions.TryTest) => {
return {type:'your_action'}
});
constructor(private actions$: Actions) {}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
