簡體   English   中英

ngrx 與 redux - 無狀態組件

[英]ngrx vs redux - stateless components

我第一次使用 ngrx/angular 8 並試圖了解使用 observable 將狀態值綁定到this上下文的角度范式是否仍然允許組件呈現/無狀態。

是否使用 angular/ngrx 執行以下操作,仍然允許組件(在這種情況下( <settings-component></settings-component> )是“Presentational/Stateless”?

//settings-component.js
this.settings$ = this.store.select(selectSettings)
//template for component
<div>{this.settings$}</div>```

//and then somewhere else in the app (notice no props):

<settings-component></settings-component>

不,不是的。 原因很簡單:它依賴於未傳入的外部“全局”狀態中的某些東西。

我對展示/無狀態 Angular 組件的理解是,它們幾乎可以在任何 Angular 應用程序中使用,而無需在模塊級別配置特定服務或其他依賴項。 他們需要的一切都通過輸入道具傳入並通過輸出道具傳遞出去。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM