[英]NgRx StoreModule.forRoot - specify metareducers when there is no root level reducer
[英]Reducer name in StoreModule.forRoot()
我的問題是為什么下面兩個突出顯示的count
的名稱需要相同才能使應用程序正常工作? 文檔說 forRoot 將減速器作為參數,但為什么 forRoot 中減速器的名稱應該與 state 相同(在這種情況下計數)? 我在文檔中的任何地方都沒有看到這一點,謝謝!
進口:[BrowserModule, StoreModule.forRoot({ count
: counterReducer })],
構造函數(私人商店:Store<{ count
: number }>){ this.count$ = store.select('count'); }
(示例來自https://ngrx.io/guide/store )
forRoot
(和forFeature
)構建 state 樹,在此示例中,您最終得到以下 state 樹:
{
count: 0
}
select
從 state 樹中讀取,您必須從頂層開始,這就是為什么需要count
,因為它從 Z9ED39E2EA931586B6A985A6942EF7 樹中讀取count
屬性。
一個更大的 state 的例子:
{
customers: {
persons: {
...
}
}
}
將導致以下 select 獲取人員
store.select('customers', 'persons')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.