Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 5 with Angular 12 : bootstrap (navbar, dropdown) interactions are blocked after get/create bootstrap instances by JavaScript

Everything (navbar, dropdown) works fine until I try to get/create bootstrap instances in the .ts files. When I insert the get/create instance js code I can't collapse the nav-menu after I expanded and the dropdown is not working either!

Here is the source code on stackblitz

If you are commenting out the following code part, everything works fine!

 var modal = new Modal('#updatePwaModal');
 modal.show();
like image 603
Arnold Vakaria Avatar asked Feb 11 '26 02:02

Arnold Vakaria


2 Answers

I found the solution that is answered in another question where the dropdown is broken when a modal instance is created. In my case, the dropdown and also the navbar was broken!

Instead of the

import { Modal } from 'bootstrap';

needed

import { Modal } from 'bootstrap/js/dist/modal';
like image 152
Arnold Vakaria Avatar answered Feb 13 '26 19:02

Arnold Vakaria


If somebody still suffers from this - above solution did not helped for me - but this one did:

import Modal from 'bootstrap/js/dist/modal'

The only change is deleting curly braces from the statement. I'm using vue 3 composition api - maybe that is where the difference comes from.

like image 26
Przeslijmi Avatar answered Feb 13 '26 17:02

Przeslijmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!