Steps to automatically close a modal in Angular 7 after selecting a link within the modal

I have a modal with a link that opens another page when clicked. However, the modal does not close when the link opens a new page. Can you help me figure out how to close the modal?

×

Important Note

We strongly advise making individual reservations for the best experience.

Continue as a couple...

Answer №1

Suppose you have a modal with the following code snippet:

In your component's HTML file:

<a (click)="goToNextPage()" >Click here</a>

Then, in the component.ts file, add the code below:

In your component.ts file:

constructor(
    private router: Router,
    public dialogRef: MatDialogRef<ModalComponent> //replace 'ModalComponent' with your actual modal component name
) { }

goToNextPage() {
    this.dialogRef.close();
    this.router.navigate(['/nextPageURL']);
}

For more clarity, refer to the official documentation.

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

TypeScript utility function that retrieves properties from an interface based on a specified type

Is there a way to create a new object type that includes only properties from another Object that match specific types, as opposed to property names? For example: interface A { a: string; b: number; c: string[]; d: { [key: string]: never }; } int ...

Ways to transfer data from TypeScript to CSS within Angular 6

Trying to work with ngClass or ngStyle, but I'm struggling with passing the value. Here's my current code: strip.component.ts import { ... } from '@angular/core'; @Component({ selector: 'app-strip', templateUrl: &apo ...

Creating dynamic styles for mat-menu in Angular Material

I'm trying to add a dynamic style to the content of a mat-menu. I know I can use the panelClass to assign a class, but my class needs to be dynamic. Angular provides [ngStyle] or simply [style.attribute] binding for such situations, but unfortunately ...

Implementing binding of JSON API responses to dropdown menus in Angular 4

In my current Angular 4 application, I am faced with the challenge of populating a dropdown menu with data from an API response. Specifically, I am struggling to retrieve the necessary information for each section from the API. The API provides data on C ...

Having difficulty aligning an image in ng2-bootstrap carousel with Bootstrap 4

I'm struggling to center an image within the ng2-bootstrap carousel. The bootstrap 4 documentation suggests that simply using the img-fluid class should suffice. <img class="img-fluid" [src]="slidez.image"> Here's the code snippet of my e ...

What could potentially occur if the sourcemap is configured to false within an Angular application?

Recently, I began learning Angular. While exploring my project files, I came across the sourcemap option in the tsconfig.json file, which is set to "sourceMap": true by default. I stumbled upon a helpful link on Stack Overflow that clarified some of my dou ...

Tips for developing a universal function using TypeScript and TypeORM

Seeking advice on creating a versatile function in TypeScript and TypeORM I currently have numerous functions structured like this: async getOrderName(id: number): Promise<string> { const order = await this.conn.getRepository(Order).find ...

When embedding HTML inside an Angular 2 component, it does not render properly

Currently, I am utilizing a service to dynamically alter the content within my header based on the specific page being visited. However, I have encountered an issue where any HTML code placed within my component does not render in the browser as expected ( ...

Troubleshooting import errors with Typescript for C3 and D3 libraries

I have recently started working on a project using the C3 graphing library within an Ionic2/Angular2 TypeScript setup. After installing C3 via npm and the type definitions via tsd, I imported it into my own TypeScript file like this: import {Component} fr ...

Combining storybook and stencil: A comprehensive guide

I'm currently working on integrating storybook with stencil, but the stencil project was initially set up with the app starter using npm init stencil. Here's how it looks I've been researching how to use stencil with storybook, but most res ...

Converting a nested JSON object into a specific structure using TypeScript

In the process of developing a React app with TypeScript, I encountered a challenging task involving formatting a complex nested JSON object into a specific structure. const data = { "aaa": { "aa": { "xxx&qu ...

Implementing computed properties: A guide to incorporating type setting

I currently have two separate interfaces defined for Person and Dog. interface Person { name: string; weight: number; } interface Dog { name: string; mass: number } const specificAttribute = isDog ? 'mass' : 'weight'; ...

Error encountered in Next.js application's build process due to sharp module

Having trouble running yarn build on the application displayed in the image below. Utilizing Plaiceholder which relies on Sharp. Everything seems to be functioning properly, but encounters a crash during the build process. Current versions being used: ...

Tips for implementing a coupon code feature on Stripe checkout in an Angular 8+ application

I need to implement an input option for entering coupons in the Stripe payment gateway when the handler is open on the front end. I currently have a Stripe window open and would like to provide users with a way to enter coupon codes. // Function to Load ...

React Router Links not displaying the associated components

I am developing a React application that utilizes React Router. I am encountering an issue where clicking on links within my BaseNav component does not render the correct components defined in my routes. I have thoroughly examined the code but cannot ident ...

What could be causing the failure to typecheck the sx prop?

Trying to implement sx prop-based styling in a React project. Looking to utilize the theme using a theme getter. While styles render correctly in the browser, TypeScript raises errors and understanding the type ancestry is proving challenging. Working e ...

How to implement a material chiplist in Angular 8 using formGroup

Struggling to include a chip list of Angular material within an Ng form? Unable to add a new chip list upon button click and uncertain about displaying the value of the array added in the new chip list. Take a look at this example: https://stackblitz.com/e ...

Refill ag-grid with fresh data

Setting up the ag-grid initialization directly from the HTML using an onGridReady method in the component file. <div style="flex-grow:1;"> <ag-grid-angular style="float:left;width: 100%; height: 201px;margin-top:10px;" class="ag- ...

I am facing an issue with TypeScript as it is preventing me from passing the prop in React and Zustand

interface ArticuloCompra { id: string; cantidad: number; titulo: string; precio: number; descuento: number; descripcion: string; imagen: string; } const enviarComprasUsuarios = ({ grupos, }: { grupos: { [key: string]: ArticuloCompra & ...

Connecting data with Angular

Recently, as part of my learning journey with Angular, I encountered an intriguing issue. While working on my code, I noticed that the error popped up in my code editor (VSCode) but not when running the code in the browser. The dilemma stemmed from settin ...