How to close a Bootstrap modal after routerlink redirection with Angular 6

FranP

I am developing my first Angular app. I have a Bootstrap modal with a button which redirects to another section of the app.

<button type="button" class="btn btn-info btn-lg" routerLink="/contactar">Contáctenos</button>

Problem is, when I get redirected to that section, the modal is somehow still enabled and the whole section is covered with the typical grey transparency behind the modals, and I am not allowed to push any button or do something on this "contactar" section.

I tried to close the modal using jQuery and modal() function, with this method on my component.ts, on the (click) event of the button.

closeModal()
{
    let mod=$(".modal")[0];
    mod.modal('hide');
} 

Like this:

<button type="button" class="btn btn-info btn-lg" (click)="closeModal()" routerLink="/contactar">Contáctenos</button>

But it throws the error "Property modal does not exist on type HTML element".

I also tried to do:

npm install -D @types/bootstrap

Like suggested here

But it doesn't work.

A solution I found is using a link with href attribute instead of that button. That way the page is loaded again, and then, no modal is activated when I get redirected to the section:

<a type="button" class="btn btn-info btn-lg" href="/contactar">Contáctenos</a>

But I don´t like it since it breaks the asynchonous advantages of Angular, and I would like to find a way to close that modal before I get redirected though the routerLink directive.

Thank you in advance.

Gary Thomas

Add the following attribute to your button to close the modal when it is clicked:

data-dismiss="modal"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

angular ui modal after close event

How to programmatically close ng-bootstrap modal?

How to close the Bootstrap modal after submit?

Refresh page after bootstrap modal close

How to save and close a bootstrap modal?

Reset validation messages after close Bootstrap modal

Angular 2 - Open/Close default bootstrap modal

Angular 2 ng-bootstrap close Modal

Angular bootstrap: how to close modal

RouterLink is not working in Angular 6

routerLink not working in Angular 6

How to validate and close bootstrap 3 modal form in Angular 5?

How to close a bootstrap modal popup after downloading a file

How to close a nativescript modal after a few navigations?

how to close pop up modal window in the bootstrap

How to trigger bootstrap modal popup after page loads in Angular 7

How to close form modal after submiting?

How to return the changes or return the value to parent after modal close in angular

how do I prevent bootstrap modal close after jquery validation on a form?

How to close bootstrap modal window from angularjs

Close angular bootstrap modal window from a controller

How to close modal after transition to another modal on angular ui router

Bootstrap modal: how to fade in, but immediately disappear on close

How to listen to bootstrap modal close event in react

How to close modal in angular 6

How to close bootstrap modal programmatically in react js

How to close bootstrap modal after submit form in React JS?

How to close modal on bootstrap after function runs vue3 composition api

Angular close a bootstrap modal conditionally