How to add JQuery and Bootstrap to an Angular CLI project

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

  1. Create your Angular CLI app

    ng new angular-app
    
  2. In your terminal, run

    npm install jquery --save
    npm install @types/jquery --save
    
  3. 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"
        ]
    }
    
  4. Open angular.json and make sure jquery has an entry in angular.json -> scripts

    ...
        "scripts": [
            "node_modules/jquery/dist/jquery.min.js"
        ]
    ...
    
  5. 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"
    	]
    

References

How to use jQuery with TypeScript

Comments

Popular posts from this blog

WPF - Combobox with a null item

Add Cordova and Electron to an Angular App

How to enable CORS between an Angular app and an ASP.Net Web API Service