rxMutation()

rxMutation(), from @ngsignal/mutation/rxjs-interop, is the counterpart of rxResource(): mutationFn returns an Observable, typically an existing service method such as http.post(). The last emitted value resolves the call once the Observable completes; reset() or destroying the component unsubscribes. Source

Reset while pending to cancel the request (an artificial 2 s delay).

status
idle
value
—
error
protected readonly createUser = rxMutation<string, User, HttpErrorResponse>({
  mutationFn: (name) => this.http.post<User>('/api/users', { name }),
});
<form (submit)="$event.preventDefault(); createUser.mutate(nameInput.value)">
  <button type="submit" [disabled]="createUser.isPending()">
    {{ createUser.isPending() ? 'Creating…' : 'Create user' }}
  </button>
  <button type="button" (click)="createUser.reset()">Reset</button>
</form>