Use MatDialog to open the next dialog when the previous one has been closed - whether you choose to use a

I'm trying to figure out how to open the next dialog from a stream only after the previous one has been closed. I want to make sure that I don't open all the dialogs in a row as soon as I get the values from the stream.

        const arraySource = from(res);

        arraySource.pipe().subscribe(code => {
          console.log('value: ', code);

          const description = this.locale.getDescription(code);
          const config      = new MatDialogConfig();
                config.data = {code: code, description: description.value};

          this.validationDialogRef = this.dialog.open(ValidationDialog, config);
          this.validationDialogRef.afterClosed().subscribe(data => {
                console.log("data returned from mat-dialog-close is ", this.validationDialogRef, data);

          });

        })

Using the take(1) operator, I am only able to get the first element from the array in the dialog. Without using take(1), all the dialogs will pop up at once. Is there a way to trigger the scheduler only when the previous dialog has been closed?

Best regards,

Answer №1

A helpful method to use in this scenario is the concat function. It ensures that the next observable is triggered only after the previous one has completed:

concat(
  ...res.map((code) => of(void 0).pipe(
    concatMap(() => {
      const description = this.locale.getDescription(code);
      const config = new MatDialogConfig();
      config.data = {code: code, description: description.value};

      this.validationDialogRef = this.dialog.open(ValidationDialog, config);

      return this.validationDialogRef.afterClosed().pipe(
        tap((data) => {
          console.log("data from mat-dialog-close:", this.validationDialogRef, data);
        })
      );
    })
  ))
).susbcribe(() => {
  // all dialogs have been processed
});

If you prefer using concatAll, the implementation would be similar. You can achieve the same result, and it can also be combined with defer:

from(res).pipe(
  map((code) => defer(() => {
    const description = this.locale.getDescription(code);
    const config = new MatDialogConfig();
    config.data = {code: code, description: description.value};

    this.validationDialogRef = this.dialog.open(ValidationDialog, config);

    return this.validationDialogRef.afterClosed().pipe(
      tap((data) => {
        console.log("data from mat-dialog-close:", this.validationDialogRef, data);
      })
    );
  }),
  concatAll()
).subscribe(() => {
  // all dialogs have been processed
});

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

Troubleshooting: Android compatibility issue with Angular Capacitor iframe

Issue with loading iframe on Android using Angular and Capacitor I have been attempting to use two different iframes in various forums, but unfortunately, it has not resolved my issue. While everything looks fine on Chrome, the iframe fails to load on And ...

String validation using regular expressions

Below is the code I am using to validate a string using regular expressions (RegEx): if(!this.validate(this.form.get('Id').value)) { this.showErrorStatus('Enter valid ID'); return; } validate(id) { var patt = new RegExp("^[a-zA- ...

What is the process for obtaining or creating scripts in the package.json file for Angular?

After browsing through the angular.io website, I'm unable to locate the package.json files in the additional documentation section. How exactly is this file created? Do I have to download it from elsewhere? ...

Transformed Vue code with TypeScript using a more aesthetically pleasing format, incorporating ref<number>(0)

Original Format: const activeIndex = ref<number>(0) Formatted Version: const activeIndex = ref < number > 0 Prettier Output: click here for image description Prettier Configuration: { "$schema": "https://json.schemastore.org ...

Use Filterpipe within Angular Template to sort content based on Object Value

I have an Object Mockup: export const IMAGES: Image[] = [ { ID: 1, NAME: 'Werk1', YEAR: 1992, IMGURL: 'assets/Images/1/img1.jpg', MATERIA ...

Changing the Background Color of MUI Dialogs

I am trying to customize the background color of my MUI dialog to black, but for some reason, it is not working as expected. I have set the colors in the theme correctly, yet the dialog color does not match the background color. This is how my Dialog comp ...

What is the step-by-step process for incorporating the `module` module into a Vue project?

ERROR Compilation failed with 6 errors 16:20:36 This specific dependency could not be located: * module in ./node_modules/@eslint/ ...

Using JavaScript to display a confirmation dialog box with the content retrieved from a text input field

Can a confirm dialog box be used to show the user-entered value from a form's text box? For instance, if the user enters 100.00, I want the dialog box to say something like, "Confirm Amount. Press OK if $100.00 is accurate." ...

Is there a way to reverse the animation playback in Angular?

I am working on an animation that involves a box fading from its original color to yellow. However, I would like to achieve the opposite effect: when the page loads, I want the box to start off as yellow and then fade back to its original color. The challe ...

Resolving the issue of 'type' property missing but required in 'SeriesXrangeOptions' within the Angular Highcharts module

I'm attempting to showcase a price chart view for a specific cryptocurrency chosen from a list of cryptocurrencies, but I keep encountering a type mismatch error. Within my application, I have utilized the angular-highcharts module and brought in the ...

Error in Angular 6: Unable to access the property 'runOutsideAngular' as it is undefined

After creating a nav-bar using the CLI with the following command: ng g @angular/material:material-nav --name=version-nav I imported it into my component as follows: <app-version-nav></app-version-nav> Unfortunately, I encountered this erro ...

The specified file cannot be located by ASP.NET Core

After following a tutorial on integrating Angular and ASP.NET Core, I encountered an error upon updating the angular packages. The specific line causing the error in my application startup code is: app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptio ...

Retrieving the text value of a selected option with a reactive form

This is my select option HTML <select _ngcontent-c3="" formcontrolname="role" value="" ng-reflect-name="role"> <option _ngcontent-c3="" value="addrole" ng-reflect-value="addrole">--Add Role--</option> <option _ngcontent-c3="" v ...

During the signin process with invalid credentials, a CallbackRouteError is thrown by Next-auth instead of the expected CredentialsSignin error while using the Credentials

I am currently engaging with the tutorials provided by Next JS, accessible at Next JS. Right now I am immersed in chapter 15. However, I encountered a peculiar issue when attempting to sign in with invalid credentials. Instead of receiving the expected err ...

Angular Material table that uses a right-to-left direction for layout

Currently, I am utilizing angular material version 7.1.1. In my setup, there is a table that has horizontal scrolling and sticky columns. Everything functions smoothly; however, when attempting to switch the display direction from right to left (as my tab ...

Notify programmers about the potential risks associated with utilizing certain third-party components

Incorporating a 3rd party library into our codebase involves utilizing its components directly, although some are enclosed within internally created components. Is there a method available to alert developers when they try to use one of the wrapped compone ...

Utilizing ngrx/store in Angular 2 for Search Functionality

In the process of enhancing an angular 4 application, I am working on integrating a search functionality for a data-filled table. The application also utilizes ngrx store to manage state. I am looking for advice on the most effective approach to implemen ...

tips for concealing the shadow of a draggable div during the dragging process

I am facing an issue with a draggable div. When I drag the div, the shadow also moves along with it. I want to find a way to hide this shadow while dragging. <div draggable="true" (dragstart)="mousedown($event)" (drag)="dra ...

The issue arises when attempting to apply a class binding to the mat-card element, as the mat-card class

When a single class binding is applied to mat-card, the mat-card class does not bind. <mat-card cdkDropList [className]="getClassName(item)"><!-- some content--></mat-card> In this scenario, the class name appears as something ...

A comprehensive guide on displaying data in Angular using an API

I have encountered an issue while trying to display data from an API in the 'home.component.html'. Although my 'home.component.ts' successfully fetches the data from the service, I'm facing difficulty rendering it in 'home.com ...