Angular ngx Bootstrap Introduction
Last Updated :
23 Jul, 2024
Angular ngx Bootstrap is an open-source (MIT Licensed) project, that provides Bootstrap components powered by Angular, which does not require including any original JS components. This framework facilitates the creation of components with great styling with very easy to use, which, in turn, helps to make interactive & responsive websites or web applications. In this article, we will know an overview of ngx Bootstrap, its basic syntax & installation procedure, along with understanding its implementation through the examples.
The ngx Bootstrap facilitates the different kinds of components for fulfilling the different purposes, such as the Alert Component can be used to provide contextual feedback messages for typical user actions with the handful of available, the Rating Component can be used to make a component that will be shown by using stars, the Progressbar Component can be used to provide up-to-date feedback on the progress of the work, etc. These components utilize the respective APIs to perform the specific task. Using these components in the angular project can help to create an attractive web application, along with enhancing overall interactivity to the site or app.
Installation Syntax:
npm install ngx-bootstrap --save
Steps for installing Angular ngx Bootstrap: Before we proceed to install the Angular ngx Bootstrap, we must have installed the Angular CLI in the system. Please refer to the Angular CLI Angular Project Setup article for the detailed installation procedure. Make sure the Angular CLI & Node Package Manager is installed properly. To check the version installed, run the below commands:
node --version
npm -V OR npm --version
ng -V or ng --version
Project Structure: After successful installation, the following project structure will appear:
Project StructureSteps for creation of Angular ngx Bootstrap Component:
- Install the angular ngx bootstrap using the above-mentioned Installation command.
- Import the required package to NgModule imports in the app.module.ts file:
import { TooltipModule } from 'ngx-bootstrap/tooltip';
@NgModule({
...
imports: [ TooltipModule.forRoot(), … ]
...
})
- Add the following script in index.html:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
- Add the specific component(that is to be used) to your app.component.html file.
- Run the application using the below command:
ng serve
It will render the app in http://localhost:4200/ automatically.
Example: This example illustrates the implementation of Angular ngx Bootstrap.
app.component.html
<div class="text-center">
<h1>GeeksforGeeks</h1>
<h3>Angular ngx Bootstrap Example</h3>
<button type="button"
class="btn btn-secondary"
[disabled]="grp"
(click)="gfg1 = !gfg1"
aria-controls="geeks1">
Disabled Button
</button>
<button type="button"
class="btn btn-primary active"
tooltip="Active Button"
placement="top"
(click)="gfg1 = !gfg1"
aria-controls="geeks1">
Button
</button>
<button type="button"
class="btn btn-danger active"
tooltip="Click Here to toggle the view"
placement="bottom"
(click)="gfg = !gfg"
aria-controls="geeks">
Click to collapse!
</button>
<div id="geeks"
[collapse]="gfg">
<div class="well well-lg card card-block card-header">
DSA Self Paced Course is specifically designed
for beginners, whether it be students or working
professionals, who want to learn the Data Structures,
can easily learn the concepts.
</div>
</div>
</div>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
gfg = false;
gfg1 = false;
grp="true";
}
app.module.ts
import { NgModule } from "@angular/core";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AlertModule } from "ngx-bootstrap/alert";
import { TooltipModule } from "ngx-bootstrap/tooltip";
import { CollapseModule } from "ngx-bootstrap/collapse";
import { AppComponent } from "./app.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [
FormsModule,
BrowserModule,
BrowserAnimationsModule,
ReactiveFormsModule,
AlertModule.forRoot(),
TooltipModule.forRoot(),
CollapseModule.forRoot(),
],
})
export class AppModule {}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1" />
<link href=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
rel="stylesheet" />
<link rel="icon"
type="image/x-icon"
href="favicon.ico" />
<link rel="preconnect"
href="https://fonts.gstatic.com" />
<link href=
"https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap"
rel="stylesheet" />
<link href=
"https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet" />
</head>
<body class="mat-typography">
<app-root></app-root>
</body>
</html>
Output:
Example 2: This example describes the grouped Button Components in Angular ngx Bootstrap.
app.component.html
<div class="text-center">
<h1>GeeksforGeeks</h1>
<h3>Angular ngx Bootstrap Example</h3>
<div class="btn-group">
<label class="btn btn-primary"
role="button">Left
</label>
<label class="btn btn-primary"
role="button">Central
</label>
<label class="btn btn-primary"
role="button">Right
</label>
</div>
</div>
app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"],
})
export class AppComponent {}
app.module.ts
import { NgModule } from "@angular/core";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { ButtonsModule } from "ngx-bootstrap/buttons";
import { AppComponent } from "./app.component";
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [
FormsModule,
BrowserModule,
BrowserAnimationsModule,
ReactiveFormsModule,
ButtonsModule.forRoot(),
],
})
export class AppModule {}
Output:
Similar Reads
Angular Interview Questions and Answers Angular is a popular framework for building dynamic web applications. Developed and maintained by Google, Angular allows developers to create fast, efficient, and scalable single-page applications (SPAs) that provide a seamless user experience. Google, Accenture, Microsoft, PayPal, Upwork, Netflix,
15+ min read
Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
15+ min read
Angular Tutorial Angular is a powerful, open-source web application framework for building dynamic and scalable single-page applications (SPAs). Developed by Google, Angular provides a comprehensive solution for front-end development with tools for routing, form handling, HTTP services, and more.Designed for buildin
4 min read
AngularJS Tutorial AngularJS is a free and open-source JavaScript framework that helps developers build modern web applications. It extends HTML with new attributes and it is perfect for single-page applications (SPAs). AngularJS, developed by Google, has been important in web development since its inception in 2009.
5 min read
Introduction to AngularJS AngularJS is a popular open-source framework that simplifies web development by creating interactive single-page applications (SPAs). Unlike traditional websites that load new pages for each click, SPAs offer a smoother user experience by updating content on the same page. AngularJS makes this possi
4 min read
Angular CLI | Angular Project Setup Angular is an open-source front-end web application framework that is used for building single-page and complex web applications. By default, angular uses TypeScript for creating logic but as the browser doesn't know typescript it converts typescript into javascript in order to make typescript under
3 min read
Angular Cheat Sheet - A Basic Guide to Angular Angular is a client-side TypeScript-based, front-end web framework developed by the Angular Team at Google, that is mainly used to develop scalable single-page web applications(SPAs) for mobile & desktop. Angular is a great, reusable UI (User Interface) library for developers that helps in build
15+ min read
Explain the Architecture Overview of Angular ? Angular is a client-side front-end framework developed by a team of developers at Google based on Typescript. It is used for building dynamic and single-page web applications (SPAs). Also, Angular is a versatile framework for building web applications and offers a wide range of features and tools to
6 min read
Component Lifecycle in Angular In Angular, Components are the fundamental building blocks of an application. Understanding the lifecycle of these components is crucial for effective Angular Development. Angular provides several lifecycle hooks that allow developers to tap into key moments in a Componentâs lifecycle and execute cu
3 min read
How to Create an Angular Project from Scratch ? To create an Angular project from scratch, we'll need Node.js and npm installed on our computer. Once installed, we can use Angular CLI, a command-line tool, to quickly set up a new Angular project with a basic structure. After creating the project, we can start coding our application using TypeScri
4 min read