admin管理员组文章数量:1292160
I'm working with Angular signals and NGXS state management, and I'm trying to create a computed signal that updates both when my input signal changes and when the store updates.
I have a lazy selector:
static searchById = (id: number) => createSelector(
[ActiveDashboardSelectors.getSlices.searches],
searches => searches.find(search => search.id === id)
);
In my component, I have an input signal for the searchId:
searchId = input.required<number>();
I want to create a computed signal that reacts both to searchId changes and to store updates. I initially tried this:
public search = computed(() => select(ActiveDashboardSelectors.searchById(this.searchId())));
However, this results in a nested Signal (Signal<Signal<Search>>
). What is the best way to write a computed signal that reacts to both my searchId input signal and state updates from NGXS?
I'm working with Angular signals and NGXS state management, and I'm trying to create a computed signal that updates both when my input signal changes and when the store updates.
I have a lazy selector:
static searchById = (id: number) => createSelector(
[ActiveDashboardSelectors.getSlices.searches],
searches => searches.find(search => search.id === id)
);
In my component, I have an input signal for the searchId:
searchId = input.required<number>();
I want to create a computed signal that reacts both to searchId changes and to store updates. I initially tried this:
public search = computed(() => select(ActiveDashboardSelectors.searchById(this.searchId())));
However, this results in a nested Signal (Signal<Signal<Search>>
). What is the best way to write a computed signal that reacts to both my searchId input signal and state updates from NGXS?
1 Answer
Reset to default 1If it is a signal of a signal, execute the signal inside to get the actual value, so that it is an ordinary signal.
Since there are two signals inside, both will get evaluated when any of them change.
Replaced select
with this._store.select
to prevent injection errors.
public search = computed(() =>
this._store.select(
ActiveDashboardSelectors.searchById(this.searchId())
)()
);
版权声明:本文标题:angular - How to make a computed Signal react to both an @Input Signal and an NGXS lazy selector? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741544976a2384540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论