Struggling with incorporating the bootstrap 4 collapse
method within the navbar component of my Angular 4 App that was built using Angular CLI.
The problem I'm facing is as follows. I've imported jquery and bootstrap using the following code:
import * as $ from 'jquery';
import 'bootstrap';
Next, I've set up an event handler to collapse the navbar when a link inside it is clicked:
$('#navbarToggleArea .nav-link').on('click', function () {
$('#navbarToggleArea').collapse('hide');
});
The code compiles successfully using either ng serve
or ng build
commands. However, at runtime, it fails as if the bootstrap plugin wasn't added to jQuery. An error is thrown when the collapse
function is called:
vendor.bundle.js:60854 ERROR TypeError: WEBPACK_IMPORTED_MODULE_1_jquery(...).collapse is not a function
My main question is: what configuration adjustments are needed to resolve this error?
You can find the code here, and specifically look at the problematic component here.