Angular e instalación de Bootstrap original (2024)

La tercer forma de instalar la última version de Bootstrap (actualmente la 5) es empleando el gestor de paquetes de Node.Js

Desde la línea de comandos, en la carpeta raiz de nuestro proyecto procedemos a instalar el paquete:

npm install bootstrap --save

La opción --save hace que npm incluya el paquete dentro de la sección de dependencies del archivo package.json en forma automática, lo que evita que tengamos que escribirlo en forma manual.

Si abrimos el archivo 'package.json' podemos ver que se han añadido las tres dependencias en nuestro proyecto:

{ "name": "proyecto038", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test" }, "private": true, "dependencies": { "@angular/animations": "~13.0.0", "@angular/common": "~13.0.0", "@angular/compiler": "~13.0.0", "@angular/core": "~13.0.0", "@angular/forms": "~13.0.0", "@angular/platform-browser": "~13.0.0", "@angular/platform-browser-dynamic": "~13.0.0", "@angular/router": "~13.0.0", "bootstrap": "^5.1.3", "rxjs": "~7.4.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "~13.0.4", "@angular/cli": "~13.0.4", "@angular/compiler-cli": "~13.0.0", "@types/jasmine": "~3.10.0", "@types/node": "^12.11.1", "jasmine-core": "~3.10.0", "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.0.3", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.4.3" }}

Como último paso para poder utilizar Bootstrap en nuestro proyecto, debemos modificar el archivo 'angular.json' donde debemos especificar el path de los 2 archivos (en la propiedad 'build', en 'styles' indicamos el path donde se encuenta el archivo *.css y en 'script' el archivo respectivo):

{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "proyecto038": { "projectType": "application", "schematics": { "@schematics/angular:application": { "strict": true } }, "root": "", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/proyecto038", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css",  "src/styles.css" ], "scripts": [ "node_modules/bootstrap/dist/js/bootstrap.min.js" ] }, "configurations": { "production": { "budgets": [ { "type": "initial", "maximumWarning": "500kb", "maximumError": "1mb" }, { "type": "anyComponentStyle", "maximumWarning": "2kb", "maximumError": "4kb" } ], "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "outputHashing": "all" }, "development": { "buildOptimizer": false, "optimization": false, "vendorChunk": true, "extractLicenses": false, "sourceMap": true, "namedChunks": true } }, "defaultConfiguration": "production" }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "configurations": { "production": { "browserTarget": "proyecto038:build:production" }, "development": { "browserTarget": "proyecto038:build:development" } }, "defaultConfiguration": "development" }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "proyecto038:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.css" ], "scripts": [] } } } } }, "defaultProject": "proyecto038"}

Con este método no debemos modificar nada el archivo 'index.html':

<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>Proyecto038</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"></head><body> <app-root></app-root></body></html>
Angular e instalación de Bootstrap original (2024)

FAQs

How do I install Bootstrap in Angular? ›

How to Add Bootstrap to Angular
  1. Prerequisites. To follow this tutorial, you will need: ...
  2. Create a Project. The next step is to build the project. ...
  3. Get Bootstrap Ready and Installed. If you're running Angular already, you'll need to open a new console window to manage the installation. ...
  4. Prepare the Features. ...
  5. Build a Modal.
Jan 25, 2023

How to add Bootstrap script in Angular JSON? ›

Angular Bootstrap via NPM

Another way to add Bootstrap to your Angular project is to install it into your project folder by using NPM (Node Package Manager). Paste the relative paths to these files in the angular. json file, under the build section.

How to install Bootstrap 4.4 1 in Angular? ›

Adding bootstrap using the angular.

Open the file and perform the following commands, node_modules/bootstrap/dist/css/bootstrap. css in the projects->architect->build->styles array, node_modules/bootstrap/dist/js/bootstrap. js in the projects->architect->build->scripts array, node_modules/bootstrap/dist/js/bootstrap.

Do we need to install Bootstrap in Angular? ›

To make building Angular web apps even easier, we often use pre-built components to build the frontend. Bootstrap provides many user interface components that let us create good-looking interactive frontends with ease. Libraries are made to create Angular components based on the Bootstrap framework.

How to install and import Bootstrap? ›

Adding Bootstrap
  1. npm install bootstrap.
  2. yarn add bootstrap. Import Bootstrap CSS and optionally Bootstrap theme CSS in the beginning of your src/index.js file:
  3. import 'bootstrap/dist/css/bootstrap.css'; ...
  4. npm install sass.
  5. yarn add sass. ...
  6. // Override default variables before the import.
Nov 4, 2021

How to check if Bootstrap is installed or not? ›

An easy way to do this, without searching files or folders would be:
  1. Open your web page on browser.
  2. press ctrl+U.
  3. search bootstrap. min. js or bootstrap. min. css, then click it (it would open source file)
  4. at first line (commented) you should see the Bootstrap version.
Mar 11, 2013

How does Bootstrap work in Angular? ›

In other words when an Angular application is started, the Angular framework reads the main. ts file, which contains the bootstrap code, and it loads the specified module ( AppModule ). The framework then processes the metadata defined in AppModule and initializes the application accordingly.

How to install Bootstrap in Angular 14 project? ›

3+ Ways to Include Bootstrap 4 In Your Angular 14 Project

Importing the Bootstrap CSS file in the global styles. css file of your Angular project with an @import keyword. Adding the Bootstrap CSS and JavaScript files in the styles and scripts arrays of the angular. json file of your project.

How to setup Bootstrap in Angular 15? ›

In this method, you simply install Bootstrap into your Angular 15 project and import its CSS file into your 'style. css' file. This step specifically covers the CSS importation process. To accomplish this, follow the command provided below.

How to add Bootstrap in Angular 13? ›

Adding Bootstrap 5 to an Angular 13 project
  1. Step 0.5: New Angular app. If you haven't already, let's create a new Angular application using: ng new name-of-app. ...
  2. Step 1: Installations. ...
  3. Step 2: Configure angular. ...
  4. Step 3: Implement & ng serve!
Dec 22, 2021

How to add Bootstrap 5 in Angular 16? ›

Here's a step-by-step guide on how to install Bootstrap in Angular.
  1. Step 1: Create a New Angular Project. ...
  2. Step 2: Navigate to Your Project. ...
  3. Step 3: Install Bootstrap. ...
  4. Step 4: Update Angular JSON. ...
  5. Step 5: Verify Installation. ...
  6. Step 6: Create a New Component. ...
  7. Step 7: Open the Card Component. ...
  8. Step 8: Add Bootstrap Card HTML.
Nov 16, 2023

How to add Bootstrap in Angular 14? ›

You can include Bootstrap in your Angular 14 project in multiple ways:
  1. Including the Bootstrap CSS and JavaScript files in the <head> section of the index. ...
  2. Importing the Bootstrap CSS file in the global styles. ...
  3. Adding the Bootstrap CSS and JavaScript files in the styles and scripts arrays of the angular.
Oct 30, 2020

How to install Bootstrap on npm? ›

Navigate to the root /bootstrap/ directory, then run npm install . npm will look at the package.json file and automatically install the necessary local dependencies listed there.

Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6089

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.