Angular ngx bootstrap Dropdowns Component - GeeksforGeeks

02 Sep, 2021
Angular ngx bootstrap is a bootstrap framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites.
In this article, we will see how to use Dropdowns in angular ngx bootstrap.
Installation syntax:
npm install ngx-bootstrap --save 
Approach:
First, install the angular ngx bootstrap using the above-mentioned command. 
 
Add the following script in index.html<link href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css” rel=”stylesheet”>
<link href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css” rel=”stylesheet”>
Import Dropdowns component in module.ts
In app.component.html, make a Dropdowns component.
Serve the app using ng serve.
Example 1:
index.html
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <base href="/">    <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>
app.component.html
<div class="btn-group" dropdown>    <button id="button-basic"         dropdownToggle type="button"         class="btn btn-success dropdown-toggle"        aria-controls="dropdown-basic">         Dropdown 1     </button>          <ul id="dropdown-basic"         *dropdownMenu class="dropdown-menu"         role="menu" aria-labelledby="button-basic">        <li role="menuitem">            <a class="dropdown-item">gfg</a>        </li>        <li role="menuitem">            <a class="dropdown-item">geeks</a>        </li>        <li role="menuitem">            <a class="dropdown-item">GeeksforGeeks</a>        </li>    </ul></div>  <div class="btn-group" dropdown>    <button id="button-basic"         dropdownToggle type="button"         class="btn btn-danger dropdown-toggle"        aria-controls="dropdown-basic">        Dropdown 2    </button>          <ul id="dropdown-basic"         *dropdownMenu class="dropdown-menu"         role="menu" aria-labelledby="button-basic">        <li role="menuitem">            <a class="dropdown-item">gfg1</a>        </li>        <li role="menuitem">            <a class="dropdown-item">geeks1</a>        </li>        <li role="menuitem">            <a class="dropdown-item">GeeksforGeeks1</a>        </li>    </ul></div>
app.module.ts
import { NgModule } from '@angular/core';  // Importing forms moduleimport { FormsModule, ReactiveFormsModule }             from '@angular/forms';import { BrowserModule } from '@angular/platform-browser';import { BrowserAnimationsModule }    from '@angular/platform-browser/animations';import { BsDropdownModule } from 'ngx-bootstrap/dropdown';    import { AppComponent } from './app.component';  @NgModule({    bootstrap: [        AppComponent    ],    declarations: [        AppComponent    ],    imports: [        FormsModule,        BrowserModule,        BrowserAnimationsModule,        ReactiveFormsModule,        BsDropdownModule.forRoot()      ]})export class AppModule { }
Output:
Reference: https://valor-software.com/ngx-bootstrap/dropdowns
ysachin2314
Angular-ngx-bootstrap
AngularJS
Bootstrap
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Angular PrimeNG Messages Component
How to change navigation bar color in Bootstrap ?
Form validation using jQuery
How to pass data into a bootstrap modal?
How to align navbar items to the right in Bootstrap 4 ?
How to Show Images on Click using HTML ?