How to add JQuery and Bootstrap to an Angular CLI project
How to add JQuery and Bootstrap to an Angular CLI project
Works with
- Angular CLI: 10.1.1
Steps
-
Create your Angular CLI app
ng new angular-app
-
In your terminal, run
npm install jquery --save npm install @types/jquery --save
-
Go to tsconfig.app.json and add an entry in the “types” array
{ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "types": ["jquery"] }, "exclude": [ "test.ts", "**/*.spec.ts" ] }
-
Open angular.json and make sure jquery has an entry in angular.json -> scripts
... "scripts": [ "node_modules/jquery/dist/jquery.min.js" ] ...
-
Follow same procedure for Bootstrap, but don’t forget to add an entry to “styles” in angular.json
"styles": [ "src/styles.scss", "node_modules/bootstrap/dist/css/bootstrap.min.css" ], "scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js" ]
Comments
Post a Comment