const apiUrl = environment.apiUrl;
export const PublisherStore = signalStore(
withState(initialState),
withComputed(({fetchStatus, saveFetchStatus}) => ({
fetchPending: computed(() => fetchStatus() === 'pending'),
saveFetchPending: computed(() => saveFetchStatus() === 'pending'),
})),
withProps(() => ({
_toastService: inject(ToastService),
})),
...
...
withMethods(() => ({
_postOffer: resource({
loader: async () => {
const post = await fetch(`${apiUrl}/api/offers`);
return await post.json();
}
})
}) as MethodsDictionary),
withMethods((store: any) => ({
...
updateDetails: (details: any) => {
patchState(store, {details});
}
})),
withLogger(STORE_KEY),
);
that's my code,
i want to call api using resource
withMethods(() => ({
_postOffer: resource({
loader: async () => {
const post = await fetch(`${apiUrl}/api/offers`);
return await post.json();
}
})
}) as MethodsDictionary),
but getting error
publisher-plotsponent.html:2 ERROR RuntimeError: NG0203: rxResource() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext
. Find more at /errors/NG0203
what do i doing wrong?
When i change WithMethods to WithProps the request is sent on store init, but its not my case. I want to link store method to button in my component
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744240586a4564684.html
评论列表(0条)