作爲新ngrx
我面臨的一個例外,不知道爲什麼......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;
影響:
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
我認爲你需要添加paranthesis('()')當你想派遣一個新的動作,否則構造不叫:'this.store.dispatch(新MyActions.TryTest({名稱: 'test'})());' – David
感謝大衛的時間,但我想我調用構造函數並傳遞對象{name:test} – Thibs
哦,對不起,我誤解了你的代碼!沒關係! – David