問題描述
NgRx Store:如何在兩個功能模塊之間共享數據 (NgRx Store : How to share the data between two feature modules)
我有使用 ngrx 的 Angular 7 應用程序。我有兩個延遲加載的功能模塊。一個是概述,另一個是儀表板模塊。概覽模塊想要訪問系統中可用的儀表板列表。
將可用儀表板數據共享到概覽模塊的最佳做法應該是什麼。我不希望將整個儀表板模塊加載到概覽模塊中。如何使用ngrx store 實現數據共享。
我可以通過編寫服務並在模塊之間共享相同的數據來輕鬆共享數據,但我想看看如何使用ngrx 實現相同的目標。
參考解法
方法 1:
Selectors! If the module is loaded, you can easily write a selector that uses a selector for Module A and/or B.
const combined = createSelector(
selectFromModuleA,
selectFromModuleB,
(a, b) => ...
)
I've written about this topic in Sharing data between modules is peanuts
(by Rahul Tokase、timdeschryver)