NgRx Store:如何在兩個功能模塊之間共享數據 (NgRx Store : How to share the data between two feature modules)


問題描述

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 Tokasetimdeschryver)

參考文件

  1. NgRx Store : How to share the data between two feature modules (CC BY‑SA 2.5/3.0/4.0)

#angular7 #ngrx #ngrx-store






相關問題

更改角度 7 中打印值的顏色 (Change the colour of printed value in angular 7)

在Angular7中更改路線的頁面重新加載問題 (Page reload issue on changing the route in Angular7)

如何使用訂閱來映射對象 (How to map object using subscribe in angular)

Angular 文件夾結構 (Angular Folder Structure)

在兄弟組件之間傳遞數據 (Passing Data between sibling components)

如何在 *ngFor 中循環選擇標籤並獲取所選值 (how to loop throught select tags inside *ngFor and get the selected value)

如何測試角度事件監聽器? (How to test angular event listeners?)

Angular 7/8 響應開發服務器上的健康檢查 (Angular 7/8 respond to health-checks on the dev server)

NgRx Store:如何在兩個功能模塊之間共享數據 (NgRx Store : How to share the data between two feature modules)

根據角度表單構建器/組中其他字段的值運行並設置一個字段的驗證錯誤 (Run and set the validation errors on one field based on the value of other field in angular form builder/group)

如何更改 Angular Material 中的標籤標籤? (How to change tab label in Angular Material?)

429 Too Many Requests - Angular 7 - 多個文件上傳 (429 Too Many Requests - Angular 7 - on multiple file upload)







留言討論