angular
  1. angular-bootstrap-via-npm

Angular Bootstrap via npm

Angular Bootstrap is a popular UI framework for developing responsive web applications. It offers a wide range of pre-built components such as forms, modals, carousels, and much more. By installing Angular Bootstrap via npm, you can quickly and easily include these components in your Angular projects.

Syntax

To install Angular Bootstrap via npm, use the following command:

npm install --save ngx-bootstrap

Example

<ng-template #modalTemplate>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Login</h4>
  </div>
  <div class="modal-body">
    <form>
      <div class="form-group">
        <label>Email</label>
        <input type="email" class="form-control" [(ngModel)]="email">
      </div>
      <div class="form-group">
        <label>Password</label>
        <input type="password" class="form-control" [(ngModel)]="password">
      </div>
    </form>
  </div>
  <div class="modal-footer">
    <button class="btn btn-primary" (click)="login()">Login</button>
    <button class="btn btn-default" (click)="cancel()">Cancel</button>
  </div>
</ng-template>

Output

The above example will produce a login modal with two form inputs, visually appearing as:

Login modal example

Explanation

Angular Bootstrap is built on top of Bootstrap, which provides a set of CSS and JavaScript files that add functionality and styling to HTML elements. Installing Angular Bootstrap via npm provides you with the framework and its dependencies, allowing you to use its components in your Angular project.

Use

To use Angular Bootstrap, you need to import the module in your Angular component:

import { ModalModule } from 'ngx-bootstrap/modal';

@NgModule({
  imports: [ ModalModule.forRoot() ],
  ...
})

After importing the module, you can use its components in your HTML templates:

<button class="btn btn-primary" (click)="showModal()">Login</button>

<ng-template #modalTemplate>
  <div class="modal-header">
    <h4 class="modal-title pull-left">Login</h4>
  </div>
  <div class="modal-body">
    <form>
      <div class="form-group">
        <label>Email</label>
        <input type="email" class="form-control" [(ngModel)]="email">
      </div>
      <div class="form-group">
        <label>Password</label>
        <input type="password" class="form-control" [(ngModel)]="password">
      </div>
    </form>
  </div>
  <div class="modal-footer">
    <button class="btn btn-primary" (click)="login()">Login</button>
    <button class="btn btn-default" (click)="cancel()">Cancel</button>
  </div>
</ng-template>

Important Points

  • Angular Bootstrap components are built on top of Bootstrap framework.
  • Import Angular Bootstrap modules in your Angular component to use its components.
  • Use pre-built components to save time on developing custom UI elements.

Summary

Installing Angular Bootstrap via npm provides you with a wide range of pre-built components that you can use in your Angular projects. By importing the Angular Bootstrap modules, you can quickly add functionality and styling to your HTML elements.

Published on: