问题标签 [ngrx-reducers]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
566 浏览

ngrx - ngrx 在效果期间两次调用减速器

我正在使用使用ngrx的角度应用程序进行开发。我已经定义了下面的约定来实现加载指示器:

  • 每个实体的初始状态设置为 null
  • 在效果开始时将其设为空对象
  • 在效果完成后用获取的数据填充它

现在我的效果之一是:

但是第一个 switchMap 中的 reducer 调用没有发生。问题是什么。

0 投票
2 回答
2184 浏览

redux - 如何使用ngFor以角度获取和显示ngrx存储数据

我将表单数据以状态存储在数组中。我正在接收数组,但它是嵌套形式的。我不知道如何显示它。

//查看Viewcomponent.ts

//viewcomponent.html

//reducer.ts

0 投票
1 回答
918 浏览

angular - “类型上不存在属性‘操作’……”createReducer() NgRx 函数中的错误

我正在重构我的 NgRx 减速器以使用该createReducer()函数而不是传统的 switch 语句,但我收到以下错误:

这是我的createReducer()函数和导出的减速器本身:

这是我的行动:

IPrice并且IUser是描述动作数据形状的接口。

我读过的关于这个的文档说,函数(我放的地方)后面state的花括号内的第二个参数应该是动作的有效负载,但是因为我正在使用我的动作,所以不像过去那样在动作中具有实际属性,并且动作本身携带数据。使用 switch 语句方法时,我可以毫无问题地访问和保存这些数据。我在这里做错了什么?createReducer(){action}createAction()payload

0 投票
1 回答
42 浏览

angular - 单元测试。调度动作后减速器不改变状态

我正在尝试执行简单的减速器测试。新的开始加载();调度这应该将 isLoading 设置为 true。不幸的是,它显示: 预期 $.isLoading = false 等于 true。

没有什么花哨。这是测试的样子:

和减速机:

0 投票
1 回答
44 浏览

arrays - 迭代ngrx8减速器

界面:

行动:

减速机:

))

效果:

使用上面的代码,我试图将数组附加到 client_name 但是我输入的值被分成数组内的多个值,我已经附加了 redux 存储它是如何迭代的。

在此处输入图像描述

例如,如果我输入了测试和测试,它应该打印一个 ['test',"testing"]

0 投票
1 回答
994 浏览

angular - 在注销 NGRX 时清除 redux 状态

行动

减速机

应用程序模块

我正在尝试在单击注销按钮时重置状态。我确实清除了本地存储,但我还需要清除 redux 状态。所以按照这个例子https://medium.com/@moneychaudhary/how-to-reset-the-state-or-clear-the-store-on-logout-in-ngrx-store-d2bd6304f8f3 但是我在元减速器上遇到错误,我需要一些帮助来解决这个问题。谢谢。我附上了错误截图

在此处输入图像描述

0 投票
1 回答
285 浏览

angular - 角度 6 中的 state.concat redux reducers 没有连接有效负载数据?

  • 减速器/index.ts

    /li>
  • 动作/通知.ts

    /li>
  • 模型/通知.ts

  • 减速器/notifications.ts

我们在 Angular 6 中生成通知,浏览器正在接收 fcm 通知,与我们尝试以 redux 状态存储的通知负载数据相同,但是在显示 redux 存储的数据时我们遇到了问题,因为负载数据没有与 redux 状态数据连接.

请告知我们哪里出错了。

0 投票
1 回答
388 浏览

angular - Call same function in reducer for multiple mat-slide-toggle/checkboxes in component.html

I'm pretty new to angular and ngrx and I'm working on a project where the user is able to generate forms. The user has the option to add, from a sidebar, multiple form-elements (e.g labels, textfields, dropwdown menus, checkboxes, etc). Next to every generated form-element there are two buttons, deleting and options, now i have to add a slide-toggle/checkbox next to these two buttons (as seen in the picture below).

Generated form elements

======================================================

component.html

reducer.ts

component.ts

======================================================

What i want

When the slide-toggle/checkbox is checked then the element should be marked as required. I want to put one method for all slider on the (change).

What is the problem

When i try to slide the slider, all sliders gonna get set on true or nothing happens (depends on what i tried). If i don't have a (change) in the html then the slider i toggle gets toggled, not the others, as soon as i put a function on the (change) the problem with all sliders or none appears.

What have i tried

I added an index to the sliders (seen in the picture above) to be sure that every slider has a different id. If i click on the sliders it loggs the correct formElement, but the slider don't get checked.

Of course i have searched on stackoverflow/google for similiar questions, this was the problem that came close to mine. Difference is that there is no ngrx and that he toggles every slider with a different method. But i guess my problem is because the slider is a two-way-binding?

What i'm gonna do next

As for every added element from the sidebar, a function (in reducer.ts) is executed that pushes a new FormElement (component.ts). I would make a function that is executed every time an element is added to FormElement that also adds a slide-toggle element, but i don't know if this is best practice

=======

As i said i'm pretty new to Angular and ngrx, if i'm missing some important basics please link articles/examples. If you need more of code or anything else i'll can update the post.

0 投票
1 回答
225 浏览

angular - 类型 User[] 与类型 'User' ngrx angular 没有共同的属性

我正在尝试使用ngrx. 下面是相关代码:

user.actions.ts:

user.effects.ts:

用户.reducers.ts:

我在user.effects.ts文件中收到以下错误:

“OperatorFunction”类型的参数不能分配给“OperatorFunction”类型的参数。类型“用户[]”与类型“用户”没有共同的属性

0 投票
1 回答
36 浏览

angular - NGRX8 减速器错误消息:类型 'number' 不可分配给类型 'ListItem[]'

我正在尝试设置 NGRX 来更新列表项数组。

这是我的减速机:

以及相关的动作

我的问题是如何正确地将新条目从减速器推送到状态数组中?目前我收到此错误