Mat Progress Bar for Tracking Fetch API Requests and Generating XLS Files

I am interested in implementing a mat progress bar to track the progress made while fetching data from the database and creating an XLSX file. The progress does not need to be exact, rough estimates and sudden changes are acceptable. Is it feasible to achieve this?

Currently, I have been using mat-spinner but I would like to switch to

<mat-progress-bar mode="determinate"></mat-progress-bar>

report.ts

export_to_excel() {
  this.downloadSpinner = true;
  this.reportService.getResponseCodeReportData()
    .subscribe({
      next: data => {
        if (data.length != 0) {
          let XlsMasterData = data
          const workSheet = XLSX.utils.json_to_sheet(XlsMasterData);
          const workBook: XLSX.WorkBook = XLSX.utils.book_new();
          XLSX.utils.book_append_sheet(workBook, workSheet, 'SheetName');
          XLSX.writeFile(workBook, 'response_code.xlsx');
        } else {
          this.showSwalmessage("No record Found!", "", "warning", true);
        }
      },
      error: (error: any) => {
        this.showSwalmessage("Something Went wrong", error, "warning", true);
      },
      complete: () => {
        this.downloadSpinner = false;
      }
    }
    );
}

report.html

<div class="body" style="text-align: center;">
    <div class="button-demo">
        <button class="btn btn-primary btn-border-radius waves-effect" tabindex="0" aria-controls="example1" type="button" (click)="export_to_excel()" mat-raised-button color="primary" style="width: 120px;">
            <div style="display: flex; align-items: center; justify-content: center;">
                <mat-spinner [diameter]="20" *ngIf="downloadSpinner"></mat-spinner>
                <div style="min-width: 80px;">Download</div>
            </div>
        </button>
    </div>
</div>

service.ts

getResponseCodeReportData(){
  return this.http.get<any[]>(`${environment.apiUrl}/responsecode-report/`);
}

Answer №1

It appears that the function getResponseCodeReportData is used to download a file, and you are interested in displaying the download progress. To achieve this, make sure to include reportProgress: true and observe: 'events' in the options of your GET request. This way, you will be able to track the progress when the HTTP event type is DownloadProgress.

For reference, you can check out an example at this link:

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

Creating a type in TypeScript with keys as values taken from another type

There is an object const navigatorNames: NavigatorNamesType = { homeNavigation: 'HomeNavigation', authNavigation: 'AuthNavigation' } with the type defined as type NavigatorNamesType = { homeNavigation: 'HomeNavigation ...

Discovering the proper way to infer type for tss-react withParams and create

Greetings to everyone and a huge thank you in advance for your generous help. I have a desire to utilize the tss-react library for styling, particularly because I will be implementing Material UI components. As I delve into some documentation, the latest A ...

Ways to effectively test public functions in Typescript when using react-testing-library

I have come across the following issue in my project setup. Whenever I extend the httpService and use 'this.instance' in any service, an error occurs. On the other hand, if I use axios.get directly without any interceptors in my service files, i ...

What is the best way to access event.target as an object in Angular 2?

Apologies for my limited English proficiency. . I am trying to write code that will call myFunction() when the user clicks anywhere except on an element with the class .do-not-click-here. Here is the code I have written: document.addEventListener(' ...

The Ionic 4 Angular App functions perfectly on Ionic devices, however, when attempting to build for the browser, it displays a frustrating

I've been working on developing an Angular/Ionic 4 app for the browser. While everything seems to be running smoothly when I use "ionic serve," the real trouble starts when I try building the app with: ionic cordova build browser --prod --release --d ...

Mocking Firestore v9 getDocs() in Jest: A Comprehensive Guide

After upgrading our webapp from Firebase v8 to v9, we encountered various issues due to the new syntax. As I am still relatively new to Jest and Firebase/Firestore, not everything is completely clear to me yet ... I am attempting to mock getDocs from fire ...

Validation of Hotel Amenity Operating Hours in Angular 2

I am a beginner in angular and I could use some guidance. I have a scenario where there are two fields for the open and close time of hotel amenities. Currently, there is no validation in place. The requirement is that until the user selects none of them, ...

Steps to troubleshoot a simple function that manages asynchronous tasks

Looking to develop a versatile function that can handle async functions, execute them, and catch any errors that may arise. Coming from a javascript background, I initially managed to create a function that did just this. However, my attempt to enhance it ...

Issue with Angular2 input not firing the change event

I am facing an issue where the (change) event is not triggered when updating an input field that is being updated from a query. Here is the HTML code for the input: <input type="text" [ngModel]="inputValue" id="itemText" (ngModelChange)="setNewItem($e ...

What is the best way to transform a Storybook typescript meta declaration into MDX format?

My typescript story file is working fine for a component, but new business requirements call for additional README style documentation. To meet this need, I am trying to convert the .ts story into an .mdx story. However, I am facing challenges in adding de ...

Utilizing Typescript with Mongoose Schemas

Currently, I am attempting to connect my Model with a mongoose schema using Typescript. Within my IUser interface: export interface IUser{ _id: string; _email: string; } I also have a User class: export class User implements IUser{ _id: string; ...

What steps should I take to create an object that can be converted into a JSON schema like the one shown here?

I'm facing a rather simple issue, but I believe there's something crucial that I'm overlooking. My objective is to iterate through and add elements to an object in order to generate a JSON structure similar to the following: { "user1": ...

Exploring the endless possibilities: Testing a never-ending stream using Jasmine Marbles

When working with my Angular service, I have implemented code that utilizes polling to display a spinner until a specific condition is met: @Inject({…}) export class SomeService { backendCall(): Observable<SomeStatusWrapper> { return this.htt ...

Ran into an issue while executing ng build --prod: The JavaScript heap has run out of memory

After executing ng build --prod, I encounter the error below. What steps can I take to resolve this issue? FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory ...

Increasing typed npm module types: a guide

I am currently working on enhancing the data types within the iam-policies npm package. My main focus is on augmenting the ConditionKey type, or any other approach that can help me achieve the desired outcome. Take a look at the types file of the package ...

Managing animations with multiple components in Angular 2+

I am currently developing an Angular application that will utilize a series of Modals in a wizard-style setup. For this project, I am utilizing the Angular-cli tool. Below is the code snippet showing how I have set up my animations: animations:[ t ...

Transferring a document to a koa-js server using formidable

Looking for some guidance with my attempted file upload process from my Ionic app to a Node.js server using koajs. I'm currently utilizing koa-body and formidable to parse the body. Below is the configuration on my server: this.app.use(formidable()) ...

Experimenting with a module reliant on two distinct services

I am facing an issue with a component that relies on a service to fetch data. The service also retrieves configurations from a static variable in the Configuration Service, but during Karma tests, the const variable is showing up as undefined. Although I ...

Unable to utilize checkboxes for filtering in Angular 2 and beyond

I am working on a project that involves showcasing a list of participants. My goal is to set up a feature that allows filtering these participants based on different providers using checkboxes in real-time. Below is a sample of the participants: [ { ...

Issue with cordova plugin network interface connectivity

I'm currently working with Ionic 2 Recently downloaded the plugin from https://github.com/salbahra/cordova-plugin-networkinterface Attempting to retrieve IP addresses without utilizing global variables or calling other functions within the function ...