【问题标题】:Angular NgRX action not recognizedAngular NgRX 动作无法识别
【发布时间】:2020-05-07 21:02:00
【问题描述】:

我已经使用 NgRX 创建了 Angular 应用程序。我添加了动作、减速器、服务和效果。但是在访问该操作时,组件代码中出现以下错误。

错误:“typeof EmployeeAction”类型上不存在属性“GetEmployees”。

找到下面的代码sn-ps:

在员工组件中:

this.store.dispatch(new EmployeeAction.GetEmployees());

员工操作.ts:

export class GetEmployees implements Action {
  readonly type = GET_EMPLOYEES;
}

The entire App code will be available in this Github repository.

https://github.com/techvenky/AngularNgRx/tree/master/src

【问题讨论】:

    标签: angular ngrx ngrx-store ngrx-effects


    【解决方案1】:

    您导入抽象类并尝试创建其属性的实例。 GetEmployees 是一个类,导入它并转向它。 所以,你的调度必须是这样的: this.store.dispatch(new GetEmployees());

    我还建议您从动作类的构造函数中的有效负载属性中删除readonly

    【讨论】:

    • 我也有同样的想法,并按照您提到的那样更改了代码。现在它工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 2018-01-22
    • 2023-03-06
    • 2020-07-27
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多