Thi*_*ibs 5 ngrx ngrx-effects angular
ngrx我是新手,但面临一个例外,不确定为什么...
我正在尝试使用dispatch,action并在中处理它effect,但我不断收到错误消息:TypeError: Actions must have a type property
动作:
export const TEST_ACTION = 'test_action';
export class TryTest implements Action {
readonly type = TEST_ACTION;
constructor(public playload: any) {
}
}
export type MyActions = TryTest;
Run Code Online (Sandbox Code Playgroud)
效果:
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) {}
}
Run Code Online (Sandbox Code Playgroud)
零件:
this.store.dispatch(new MyActions.TryTest({ name: 'test' }));
Run Code Online (Sandbox Code Playgroud)
我在用:
效果:4.0.5,存储:4.0.3
如果这有助于其他人开始......结果证明我没有返回 ngrx 在地图运算符中期望的操作。
因为效果必须在最后返回一个动作。因此,您有两种选择:
从“ ./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) {}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9029 次 |
| 最近记录: |