[英]How to get and update data from the ngrx store into Observable variable?
[英]How to get Value instead of Observable from NGRX Store in TS code
考慮以下代碼
user$ = this._store.pipe(select(UserSelectors.selectUser));
現在我們有了一個可以像這樣使用的 Observable:
(user$ | async)?.name
let storeValue: IUser;
this.user$.pipe(take(1)).subscribe(value => storeValue = value);
所以在我的組件中,我實現了一個 getter:
protected get user(): IUser {
let storeValue: IUser;
this.user$.pipe(take(1)).subscribe(value => storeValue = value);
return storeValue;
}
我想知道是否有辦法使用選擇器返回實際值,例如:
user = this._store.VALUE(select(UserSelectors.selectUser));
所以我所有的getter邏輯都得到了照顧。
這是不可能的。 我什至會說這是一種反模式。
NgRx 是一個 Redux 實現,專為反應式編程而設計。
反應式:
您的方式不是被動的,這就是為什么它不適用於 NgRx。 您可以在沒有商店的情況下完成,或者您必須找到一種被動的方式來解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.