I'm having this issue in an Angular 7 app. I was not able to reproduce it with pure Bootstrap CSS/JS and Popper.js.
I'm trying to use vanilla Bootstrap JS and jQuery because I need Bootstrap's toasts and the other libs (ng-bootstrap and ngx-bootstrap) don't support toasts for the moment.
Minimal (non) working example
https://github.com/Crocmagnon/angular-bootstrap4-dropdown-issue
Run it with npm run start
Link to issue in Popper.js repo
I tried to ask the developer but he's clueless : https://github.com/FezVrasta/popper.js/issues/748
Steps to reproduce the problem
To reproduce with the example :
npm i -g @angular/cli
git clone https://github.com/Crocmagnon/angular-bootstrap4-dropdown-issue.git
cd angular-bootstrap4-dropdown-issue
npm i
ng serve
To reproduce from scratch :
- Create an angular app with ng-cli
- Install bootstrap and bootstrap types:
npm install --save bootstrap @types/bootstrap.@types/bootstraprequirespopper.jsas a dependency.
- Include Bootstrap 4 CSS and JS files
- Include Popper JS UMD file
- Add
import 'bootstrap';somewhere to tell typescript that the jQuery.tooltip()function exists - Try to use Bootstrap 4 dropdown in navbar
Relevant excerpt from angular.json :
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/@fortawesome/fontawesome-free/css/all.css",
"src/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.slim.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/js/dist/util.js",
"node_modules/bootstrap/js/dist/alert.js",
"node_modules/bootstrap/js/dist/button.js",
"node_modules/bootstrap/js/dist/carousel.js",
"node_modules/bootstrap/js/dist/collapse.js",
"node_modules/bootstrap/js/dist/dropdown.js",
"node_modules/bootstrap/js/dist/modal.js",
"node_modules/bootstrap/js/dist/scrollspy.js",
"node_modules/bootstrap/js/dist/tab.js",
"node_modules/bootstrap/js/dist/toast.js",
"node_modules/bootstrap/js/dist/tooltip.js",
"node_modules/bootstrap/js/dist/popover.js"
]
What is the expected behavior?
The dropdown should toggle
What went wrong?
The dropdown doesn't toggle at all
Comments
I tried to include Popper ESM files in my angular.json file. Everything now works fine, except that I get an error in the console.
Uncaught SyntaxError: Unexpected token export
Do I miss something here ?
Edit
It seems that this statement in main.ts breaks the dropdown :
import 'bootstrap';
However, if I remove it, Typescript screams when I want to do some Bootstrap jQuery like displaying toasts or tooltips :
$(() => {
$('[data-toggle="tooltip"]').tooltip();
});
ng-bootstrapandngx-bootstrapdon't have toasts, which I need in another part of my app, that's why I went with vanilla Bootstrap JS + jQuery. I'm adding this to the question.import 'bootstrap';