How to add Bootstrap to an Angular application

Angular is a great web development platform. In particular, adding the Bootstrap CSS framework to Angular makes the interface elements richer and more dynamic.

Angular is a great web development platform. In particular, adding the Bootstrap CSS framework to Angular makes the interface elements richer and more dynamic.

 

Condition

Before you begin, you need to install and configure the tools below to create your Angular application.

  • Git : Use this version control system to synchronize repositories.
  • Node.js and npm: Node.js is a JavaScript runtime code tool based on Google's V8 engine. Npm is a package manager for Node.js (Node Package Manager). These tools are used to build and run Angular applications, as well as install libraries.
  • Angular CLI: This is a command-line utility tool for Angular. We will use it to create the basic structure for our Angular app.
  • An IDE, like Visual Studio Code or WebStorm, is a graphical interface tool that helps you develop applications.

How to create an Angular application

Angular is a programming platform for building web, mobile, and desktop apps using HTML, CSS, and TypeScript. To create applications with the Angular framework, you can use @angular/clirouting files and SCSS formatting.

 

ng new angular-bootstrap ? Would you like to add Angular routing? Yes ? Which stylesheet format would you like to use? SCSS [ https://sass-lang.com/documentation/syntax#scss ] CREATE angular-bootstrap/README.md (1062 bytes) CREATE angular-bootstrap/.editorconfig (274 bytes) CREATE angular-bootstrap/.gitignore (604 bytes) CREATE angular-bootstrap/angular.json (3273 bytes) CREATE angular-bootstrap/package.json (1079 bytes) CREATE angular-bootstrap/tsconfig.json (783 bytes) CREATE angular-bootstrap/.browserslistrc (703 bytes) CREATE angular-bootstrap/karma.conf.js (1434 bytes) CREATE angular-bootstrap/tsconfig.app.json (287 bytes) CREATE angular-bootstrap/tsconfig.spec.json (333 bytes) CREATE angular-bootstrap/src/favicon.ico (948 bytes) CREATE angular-bootstrap/src/index.html (302 bytes) CREATE angular-bootstrap/src/main.ts (372 bytes) CREATE angular-bootstrap/src/polyfills.ts (2820 bytes) CREATE angular-bootstrap/src/styles.scss (80 bytes) CREATE angular-bootstrap/src/test.ts (743 bytes) CREATE angular-bootstrap/src/assets/.gitkeep (0 bytes) CREATE angular-bootstrap/src/environments/environment.prod.ts (51 bytes) CREATE angular-bootstrap/src/environments/environment.ts (658 bytes) CREATE angular-bootstrap/src/app/app-routing.module.ts (245 bytes) CREATE angular-bootstrap/src/app/app.module.ts (393 bytes) CREATE angular-bootstrap/src/app/app.component.scss (0 bytes) CREATE angular-bootstrap/src/app/app.component.html (23809 bytes) CREATE angular-bootstrap/src/app/app.component.spec.ts (1090 bytes) CREATE angular-bootstrap/src/app/app.component.ts (222 bytes) ✔ Packages installed successfully. Successfully initialized git.

Now we need to install Bootstrap and its libraries bootstrap-icons, which contain the files with Bootstrap styles and JavaScript code as follows:

npm install bootstrap bootstrap-icons

After installation, we will configure the Bootstrap libraries bootstrap-icons. Modify the file angular.jsonand add the following files bootstrap.scss: , bootstrap-icons.css, bootstrap.bundle.min.jsas shown below:

 

"styles": [ "node_modules/bootstrap/scss/bootstrap.scss", "node_modules/bootstrap-icons/font/bootstrap-icons.css", "src/styles.scss" ], "scripts": [ "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js" ]

Now we will install the @ng-bootstrap/ng-bootstrapnative Angular support library:

npm install @ng-bootstrap/ng-bootstrap@next

After installation, we will import the module NgbModule. Modify the file app.moduleand add the lines below:

import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; imports: [ BrowserModule, NgbModule, AppRoutingModule, ],

Now we will remove the contents of the AppComponent class from the file src/app/app.component.ts. Import the service NgbModaland create an open method to open a modal as shown below.

import { Component } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) export class AppComponent { constructor(private modalService: NgbModal) { } public open(modal: any): void { this.modalService.open(modal); } }

Next, we will delete the contents of the file src/app/app.component.html. Add some HTML elements to view and inspect the elements as shown below.

   
Related posts
  • How to customize Bootstrap with Sass

    bootstrap is a fantastic css framework that can help you create stylish and polished websites. some programmers and development teams find that writing code in bootstrap is easier to edit than regular css.
  • Update the latest Bootstrap

    with the latest version, bootstrap 5.3.0, this framework has introduced a set of exciting new features and powerful improvements for multi-purpose web and app development.
Other Program articles
  • How to build a login screen with React and Bootstrap

    Ở bài viết này, hãy cùng tipsmake.com.com tìm hiểu cách xây dựng một màn hình đăng nhập đơn giản nhưng đẹp mắt bằng react và bootstrap 5 nhé!
  • How to use Bootstrap with HTML

    dùng bootstrap với html có thể khá khó với người mới bắt đầu. thế nhưng, đừng lo, hướng dẫn từng bước dưới đây sẽ giúp bạn biết cách sử dụng bootstrap với html nhanh chóng.
  • A compilation of exercises on Bootstrap 5.

    bạn có thể kiểm tra kỹ năng về bootstrap 5 qua những bài tập được chia theo từng phần dưới đây. giải bài tập bằng cách điền vào phần code còn thiếu. bạn sẽ nhận được 1 điểm cho mỗi câu trả lời đúng.
  • Answering frequently asked questions about Bootstrap

    bootstrap là phương tiện phát triển web, ứng dụng phổ biến. nhằm giúp bạn hiểu rõ hơn, tipsmake.com.com sẽ tổng hợp và giải đáp những câu hỏi thường gặp về bootstrap.
  • Lesson 42: Large Grid in Bootstrap 5

    phần bài học bootstrap trước đã giới thiệu cho bạn những ví dụ về hệ thống lưới với các class cho thiết bị nhỏ và trung bình. Ở bài này, chúng ta sẽ tiếp tục tìm hiểu về lagre grid.
  • Lesson 41: Grid Medium in Bootstrap 5

    Ở bài học bootstrap 5 trước, bạn đã biết cách tạo grid với các class cho thiết bị màn hình nhỏ. thế nhưng trên thiết bị trung bình có thiết kế tốt hơn sẽ thường được chia theo 50%/50%.
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup