Create Entity with signalStore and rxMethod

174 Views Asked by At

I have an error message that I understand, but I don't know how to resolve it. The 'add' call works without HTTP and 'rxMethod.' However, this method cannot be loaded outside of the constructor. What am I doing wrong?

addEntity: (entityToPush: entity) => {
          return rxMethod(pipe(
            tap(() => patchState(entityStore, {isLoading: true})),
            switchMap(() => entityHttpService.createEntity(entityToPush).pipe(
              tapResponse({
                next: (entityToPush) => patchState(entityStore, {entities: [...entityStore.entities(), entityToPush]}),
                error: console.error,
                finalize: () => patchState(entityStore, {isLoading: false})
              })
            ))
          ));

error: rxMethod() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with

1

There are 1 best solutions below

0
NgDaddy On