Bootstrap 5 Popover Error - Cannot find name 'bootstrap'
Asked Answered
L

1

7

I am trying to create a popover in the Javascript of my Angular 12 project. I am using Boostrap v5.0.1. I can't seem to get rid of a name error when I am trying to create the popover:

 var exampleEl = document.getElementById(item.name + index);
 var tooltip = new bootstrap.Popover(exampleEl, {
    container: 'body',
    animation: true
 });

Typescript is telling me "Can't find name bootstrap".

I have added bootrap.js to my angular.json file:

"scripts": [
   "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
]

According to the docs, popper.js is included in the bundle file. I am not using jQuery and do not want to include it. I have not seen another post with a similar issue so I must be just overlooking something small. Any ideas?

Libya answered 1/7, 2021 at 20:39 Comment(0)
L
11

Posting this declaration at the top of the file worked:

declare var bootstrap: any;
Libya answered 17/10, 2021 at 19:12 Comment(2)
I was experimenting with a bootstrap menu inside an angular component, and had this same error. adding this code under the import fixed it.Depute
Same for me @greg. Is there anything else to consider with this solution?Gluteal

© 2022 - 2024 — McMap. All rights reserved.