rxjs - Angular signalStore and HttpResource - Stack Overflow

const apiUrl = environment.apiUrl;export const PublisherStore = signalStore(withState(initialState),wi

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

相关推荐

  • rxjs - Angular signalStore and HttpResource - Stack Overflow

    const apiUrl = environment.apiUrl;export const PublisherStore = signalStore(withState(initialState),wi

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信