I am currently working on a project that utilizes Angular 11 and we are aiming to integrate Bootstrap 5 native JS without relying on third-party libraries like ng-bootstrap, MDB, or ngx-bootstrap (jQuery is not being used as well). I understand that using JS libraries in TS may not be the best practice.
The main issue lies in how to import Bootstrap JS and utilize its objects and methods within Angular's TS components
Initially, my belief was that installing the following packages would suffice:
npm i bootstrap@next
npm i @types/bootstrap
Both packages have been successfully imported into package.json
and are present in node_modules
. Additionally, I included
"scripts": [ "node_modules/bootstrap/dist/js/bootstrap.js" ]
in angular.json
, however, I still encounter difficulties utilizing them.
For instance, when attempting:
import { Carousel } from 'bootstrap';
...
carousel: Carousel | any;
...
this.carousel = document.getElementById('video-carousel')
this.carousel.interval = false;
In this case, where 'bootstrap'
is sourced from '@types/Bootstrap'
. The carousel should not cycle automatically, yet it does. This challenge persists with other types of Bootstrap elements as well.