Troubleshooting: Solving the issue of the exhaustMap operator in HTTP request only being executed once

One of my challenges is dealing with multiple button clicks that trigger HTTP requests and receive data from the server. I'm looking for a way to prevent users from clicking the button again until the previous request is complete.

I found a solution using the exhaustMap operator from the RXJS library, but it only works on the first click. Subsequent clicks after the HTTP request has completed (whether successful or with an error) do not have any effect.

How can I overcome this issue?

HTML

<button #rescheduleButton  type="button" class="btn btn-primary">
     Get Data                
</button>

TYPESCRIPT

@ViewChild('rescheduleButton', {static: false}) rescheduleButton: ElementRef;
clicks$: Observable<any>;

public ngAfterViewInit() {
    const button = this.rescheduleButton.nativeElement;
    this.clicks$ = fromEvent(button, 'click');
    this.clicks$.pipe(
        exhaustMap(() => this.slotService.getAllAvailableSlots())
    ).subscribe((slots) => {
        console.log(slots, 'slots');
    })}

Answer №1

To ensure the operation repeats and properly handles errors, make sure to include a repeat operator at the end.

 this.clicks$.pipe(
        exhaustMap(() => this.slotService.getAllAvailableSlots()),
        catchError(e=>of(e)),
        repeat()
    )

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way for me to retrieve the value that has been set within the cy.get() function in Cypress using Typescript?

Is there a way to retrieve the value of the getLength function without it returning undefined? How can I access the value in this case? Here is my code snippet: const verifyValue = () => { const selector = 'nz-option-container nz-option-item&apo ...

What methods are available for altering state in Server Actions in NextJS 13?

Struggling to Implement State Change in NextJS 13 Server Actions I have encountered a challenge with altering state within the execution of server actions in NextJS 13. The scenario involves an actions.ts file located at the root of the app directory. Cur ...

Encountering an issue while attempting to initiate a nested array: "Cannot assign a value to an optional property access in the left-hand side of an assignment expression."

I am dealing with an object that contains nested arrays, structured like this: export class OrdenCompra { public id?: number, public insumos?: OrdenCompraInsumo[], } export class OrdenCompraInsumo { id?: number; traslados?: IImpuestoTraslado[]; } export ...

Modular Angular Component

I'm currently developing a language learning application using Angular 15. With numerous pages and components featuring diverse content, I am exploring the option of allowing users to customize the font type, size, and other display settings for each ...

Trouble with line breaks in expandable rows of data grid causing clarity issues

Exploring the expandable rows feature of Clarity datagrid for the first time. I initially thought I could insert any HTML code within the collapsed view to show content. Using VMware's expandable datagrid: However, I am facing an issue where even wh ...

Angular Material drag and drop coupled with cdk virtual scrolling can lead to unexpected jumps in the previousIndex

In my Angular app using Angular Material, I've incorporated drag and drop lists including one with virtual scrolling. However, I encountered an issue where the drop event's previousIndex value unexpectedly changes to different values for certain ...

Encountering a configuration error in the Nginx.conf file while attempting to use

I recently obtained a Visual Studio solution that includes multiple projects. https://i.sstatic.net/HuRyl.jpg A Nginx.conf file was created in ClientApp/Angular. https://i.sstatic.net/CN65e.jpg This is my docker-compose file: clientapp: image: ${DOCKER ...

Steps for deploying a Node.js and Angular project on Heroku

Struggling to host an Angular and Node.js application on Heroku, but encountered an application error. Tried numerous solutions without success. Seeking assistance in resolving the hosting issue. 1 View logs ...

security fails to redirect promptly

There seems to be an issue with the page not redirecting correctly when using "the guard," resulting in the URL staying as http://localhost:8100/ instead of http://localhost:8100/auth, which causes a blank page to display. In the file auth.guard.ts: canL ...

Change the parent title attribute back to its original state

This is in contrast to queries similar to the one referenced here. In my scenario, there is a child element within a parent element (specifically a matSelect within a matCard, although that detail may not be significant) where the parent element has a set ...

Error message indicating the Ionic 5 Phonegap-NFC plugin is not installed, even though it has been successfully installed

While utilizing the NFC library, I followed the Ionic documentation recommendations at (https://github.com/chariotsolutions/phonegap-nfc) and (https://ionicframework.com/docs/native/nfc). However, when trying to access the code in my component that calls ...

Getting Started with Angular: Loading Data into a List from a Service

As I am relatively new to Angular, I have a list that needs to be displayed on the screen. Initially, I was able to show the list with hard-coded data, but now I need to fetch the data from my service that calls an API. The data retrieval part is already i ...

The concept of window.trustedtypes is not defined within the Firefox browser

My application has successfully integrated trusted types. It is functioning well in Chrome, however, I am encountering an error in Firefox where it says "window.trustedtypes is undefined". Can anyone provide guidance on how to address this issue? ...

What methods can you use to identify obsolete or inactive code within an Angular project?

For over a year, my team and I have been dedicated to developing an innovative angular application. As we engage in the ongoing process of code refactoring, our objective is to eliminate any unnecessary or obsolete code from our repository. We are seeking ...

Testing the functionality of an Angular service with unit tests

I am a beginner when it comes to writing unit tests and currently trying to understand how to write a test for a service that is injected into a component. Component: constructor(private _assessmentService: AssessmentDataService){ } ngOnInit(){ con ...

Implementing strict type enforcement for the `toString` method

Is there a way to prevent the compiler from overloading toString? I've tried using the never type, but it still allows implicit assignments and only raises an error when something is done with the variable. It's inconvenient to remember to explic ...

Error message: The attempted import failed because ' is not exported from the module

I am facing an issue with resolving my problem. In a file named lama.d.ts, I have declared a class using the following code: export declare class lama { // code here } After that, I tried to import this class in another file within the same folder ...

Whenever a query is entered, each letter creates a new individual page. What measures can be taken to avoid this?

Currently, I am working on a project that involves creating a search engine. However, I have encountered an issue where each time a user types a query, a new page is generated for every alphabet entered. For instance, typing 'fos' generates 3 pag ...

Understanding the expiration date of a product

I'm seeking assistance with identifying expiration dates from a list of data. For instance, if I have a list containing various dates and there is an expireDate: 2019/11/20, how can I highlight that date when it is 7 days away? Here's an example ...

Dynamic data manipulation with Angular ReactiveForms

One of the challenges I am facing involves using formArray for my list of products. Specifically, I am trying to access the value of product_code in my .ts file similar to [ngModel] so that I can manipulate the data accordingly. Can anyone provide guidance ...