Step-by-step guide on implementing a mat-progress bar following the display of a dialog box

On one of my pages, there is a Run button. Clicking on this button opens a dialog box with two options: Yes and No. When the user selects Yes, I want to display a mat-progress bar. I am unsure about where to place the HTML code for the mat-progress bar or how to call it.

HTML Code:

<mat-toolbar>
                        <div class="col-md-offset-11">
                            <button
                                mat-raised-button
                                mat-hint="Execute Query on Whole DataSet"
                                color="primary"
                                (click)="executeOnFullData()"
                            >
                                Run
                            </button>
                        </div>
                    </mat-toolbar>

TypeScript Code:

    executeOnFullData() {
    const dialogRef = this.dialog.open(ConfirmJobRunComponent, {
    });

    dialogRef.afterClosed()
}

HTML Code for the Dialog Box:

<div class="card">
<div class="card-header"><h5 class="title">Confirm</h5></div>
<div class="content">
    <h3 mat-dialog-title>
        Are you sure you want to run Recommendation Settings on the entire
        Dataset?
    </h3>

    <div mat-dialog-actions>
        <button
            mat-button
            [mat-dialog-close]="true"
            (click)="confirmSelection()"
        >
            Yes
        </button>
        <button mat-button (click)="onNoClick()">
            Cancel
        </button>
    </div>
</div>

Typescript Code for Dialog Component:

import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material";
import { Component, Inject } from "@angular/core";
import { RecommendationService } from "../../recommendation- 
service.service";

@Component({
selector: "app-confirm-job-run",
templateUrl: "./confirm-job-run.component.html",
styleUrls: ["./confirm-job-run.component.scss"]
})
export class ConfirmJobRunComponent {
constructor(
    public dialogRef: MatDialogRef<ConfirmJobRunComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
    public dataService: RecommendationService
) {}

onNoClick(): void {
    this.dialogRef.close();
}

confirmSelection(): void {}
}

Answer №1

To handle the response from a dialog in Angular, you can subscribe to the afterClosed event of your dialogRef. Depending on the result (true for Yes, false for No), you can then display a mat-progress and proceed with your business logic.

For an example, check out this stackblitz demo: Here. The mat-progress shown is currently indeterminate and waiting for your customization.

Template snippet (in the component with the button)

<mat-progress-bar *ngIf="showMatProgress" mode="indeterminate"></mat-progress-bar>

Component code for the template above

showMatProgress: boolean = false;

executeOnFullData() {
  const dialogRef = this.dialog.open(ConfirmJobRunComponent, {});

  dialogRef.afterClosed().subscribe((result) => {
    this.showMatProgress = result;
  });
}

In your dialog component:

onNoClick(): void {
  this.dialogRef.close(false);
}

confirmSelection(): void {
  this.dialogRef.close(true);
}

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

Adjust jqGrid dimensions automatically as browser window is resized?

Does anyone know of a method to adjust the size of a jqGrid when the browser window is resized? I attempted the approach mentioned here, but unfortunately, it does not function correctly in IE7. ...

Is it an AJAX JavaScript error or does the breakpoint point to the view state?

I encountered a javascript error on submit in my aspx page, with the breakpoint located within the __VIEWSTATE input html element. This error is causing an "Object Expected" issue. The javascript stack dump only displays "{anonymous}(null)". I'm uns ...

Coffeescript consistently compiles indented code beyond the function scope

This is an example of Coffeescript compiling the code below $ -> $("#debug").val "hey" for i in [0..3] m = new Message(5,5) text = "<div>#{m.message[m.message_id]}</div>" $("body").append(text) which transfo ...

Using Spring Portlet to send an Ajax post request to the Controller with Jquery

EDIT: The start and end dates are stored as joda DateTime in the POJO and I am encountering the following error: SystemOut O 14:10:16.040 [WebContainer : 2] DEBUG org.springframework.beans.BeanUtils - No property editor [org.joda.time.DateTimeEditor] ...

The concept of nested views in Angular UI-Router allows for a

How can I successfully implement nested views, where after logging in the user is redirected to in.html, and all links within in.html are directed to a ui-view? Currently, all links redirect to a new page. index.html <!-- more HTML --> <body ng- ...

Can I bypass an invalid SSL certificate when making a request using a JavaScript library?

Is it possible to bypass invalid SSL certificates when using the widely-used request library? You can find more information about the library here: https://www.npmjs.com/package/request I am currently integrating this library into a Node.js server to send ...

Any ideas on how to extract binary data from PHP passthru using a JavaScript ajax request?

I am facing an issue with retrieving and playing an audio file from a server using JavaScript. The ajax call in my code doesn't seem to callback, and I'm not certain if I'm handling the audio correctly in JavaScript. Below is the PHP file t ...

Rebooting checkbox data with AJAX on MVC 5 form submission

Within my application, I am utilizing an AJAX BeginForm: @using (Ajax.BeginForm("DeletePages", "Home", new AjaxOptions { HttpMethod = "POST", OnSuccess = "OnSuccessDelete", OnFailure = "OnFailureDelete" }, new { id = "ToolBarActionsForm" })) { @Html.A ...

Load the data of the app component in Angular 2 once a user has successfully logged in on a different

I am having an issue with my app.component where the user's email is not showing in the top menu immediately after logging in and being redirected to the data list page. The email only appears after I reload the page. What I need is for the email to ...

fresh map from Google: Coordinates LatLng may not be a number, but my hunch tells me it is

Seeking Assistance with this Issue - For example, the initial location data appears as: "Object Lat: -36.768498 Lng: 174.75895" However, an error is indicating that the latitude is not recognized as a number. Rather than making adjustments without clea ...

Issue with the functionality of extended constraints in class inheritance

I have the following classes: export abstract class Parent<T> { ... public abstract <C extends Parent<T>>clone(): C; } export class Child extends Parent<number> { ... public <Child>clone(): Child { r ...

cdkVirtualFor failing to display complete list of items

Having a minor issue that I can't seem to figure out the cause of. My goal is to display a list from an observable (it contains 3 objects) However, only the first two items are showing up. When I use a regular list, all three of them appear. What cou ...

Retrieving the recently uploaded image by utilizing file upload functionality and resizing it

Having trouble retrieving the height and width of the currently selected image while uploading images using file upload. What parameters should I pass to the imageCompress function in order to obtain the dimensions of the uploaded image? function onSele ...

There seems to be a disconnect between the React Redux store

When attempting to connect my store to a React application, I encountered the following error: TypeError: state is undefined store/index.js (Creating Reducer function) import {createStore} from 'redux'; const counterReducer = (state:{counter:0} ...

"Utilizing AJAX for Data Retrieval in a Form with Dynamically Generated

Hey there, I'm trying to figure out how to make my ajax data call dynamic. Here's what I've attempted: var opt_name = $(".NAME").data('opt_name'); var opt_business = $(".BUSINESS").data('opt_business&ap ...

A more efficient method for refreshing Discord Message Embeds using a MessageComponentInteraction collector to streamline updates

Currently, I am working on developing a horse race command for my discord bot using TypeScript. The code is functioning properly; however, there is an issue with updating an embed that displays the race and the participants. To ensure the update works co ...

There must be at least one field in the Zod Schema Validation

Could someone help me translate this code from JOI to ZOD? In the JOI implementation, the user is required to send the userId and at least one key from the body. How can I achieve the same result using ZOD? params: Joi.object().keys({ userId: Joi.r ...

The malfunctioning buttons are a result of embedding PHP code within a JavaScript if-query

I am experiencing an issue where my buttons are not functioning properly, preventing me from clicking on them. All variables have been correctly assigned values. Can someone assist me in resolving this? Thank you. ?> <script> ...

React.js input elements are failing to update following a successful array modification

I'm working with a group of input fields that are dynamically created based on an array. These input fields should initially display a '?'. When a user enters a letter into one of the inputs, I want the onchange event to trigger and update t ...

Using Firebase Authentication in Next.js with Server-Side Components

As I explore how to implement authentication using Firebase in my Next.js app, one thing that stands out is the need to initialize Firebase with our configuration details (apiKey, etc.). The concern I have is when using any Firebase function from a client ...