简体   繁体   English

如何使用 NgRX 数据更新存储?

[英]How to update Store with NgRX Data?

My component structure我的组件结构

在此处输入图像描述

In case.component im caching the case data in Case entity of store then i fetch that from child components (case-actions, case-activity... etc).如果 case.component 将案例数据缓存在商店的案例实体中,那么我从子组件(案例操作、案例活动......等)中获取该数据。

But when i update remotely the Case from any child component I dont know how to refresh the cached data in parent component (case.component) to replicate that on child components again.但是当我从任何子组件远程更新案例时,我不知道如何刷新父组件(case.component)中的缓存数据以再次将其复制到子组件上。

Im trying to do with best practices.我正在尝试使用最佳实践。

Best practice:最佳实践:

  • You shouldnt fetch the data from a child component, the parent should fetch the data then pass it to the children using an @Input() and you should update your store from the parent aswell by using an @Output() that is triggered by the children.您不应该从子组件获取数据,父组件应该获取数据然后使用@Input()将其传递给子组件,并且您还应该使用由触发的@Output()从父组件更新您的商店孩子们。 That way, the parent(container) have almost all the logic.这样,父(容器)几乎具有所有逻辑。

Quick fix that I don't recommend:我不推荐的快速修复:

  • If you just want a fix, subscribe to your selector in the children and emit the value to the parent using an @Output()如果您只想修复,请在子项中订阅您的选择器并使用@Output()将值发送给父项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM