Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Bootstrap navbar in ngx-bootstrap for Angular 5?

Bootstrap navbar doesn't exist in the ngx-bootstrap components list. Please help me to implement it.

like image 453
Hossein Bajan Avatar asked Jan 02 '18 09:01

Hossein Bajan


People also ask

Can we use NG Bootstrap and NGX-bootstrap together?

This means that if you need to use Bootstrap version 3, then ngx-bootstrap is your only real option of the two. If you can use Bootstrap 4, then you can pick between the two projects.

How do I add a navigation bar in Bootstrap?

To create a collapsible navigation bar, use a button with class="navbar-toggler", data-toggle="collapse" and data-target="#thetarget" . Then wrap the navbar content (links, etc) inside a div element with class="collapse navbar-collapse" , followed by an id that matches the data-target of the button: "thetarget".

How navbar is implemented in Bootstrap?

Step 1: Include Bootstrap and jQuery CDN into the <head> tag before all other stylesheets to load our CSS. Step 2: Add <nav> tag with . navbar and . navbar-default class in <body> tag.

How do I create a vertical navigation bar in Bootstrap 5?

A standard navigation bar is created with the .navbar class, followed by a responsive collapsing class: .navbar-expand-xxl|xl|lg|md|sm (stacks the navbar vertically on xxlarge, extra large, large, medium or small screens).


2 Answers

There's no implementation of navbar as a separate component but it can be done with Collapse Module.

Example = https://stackblitz.com/edit/ngx-bootstrap-rc8ab4?file=app%2Fapp.component.ts

MODULE

// App imports import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser';  import { AppComponent } from './app.component'; import { CollapseModule } from 'ngx-bootstrap/collapse';  @NgModule({   imports:      [ BrowserModule, CollapseModule.forRoot()],   declarations: [ AppComponent ],   bootstrap:    [ AppComponent ] }) export class AppModule { } 

TS (excerpt)

export class AppComponent  {   isCollapsed = true; } 

HTML

<nav class="navbar navbar-default">   <div class="container-fluid">     <div class="navbar-header">       <button type="button" class="navbar-toggle collapsed" (click)="isCollapsed = !isCollapsed" aria-expanded="false">         <span class="sr-only">Toggle navigation</span>         <span class="icon-bar"></span>         <span class="icon-bar"></span>         <span class="icon-bar"></span>       </button>       <a class="navbar-brand" href="#">Brand</a>     </div>     <div class="collapse navbar-collapse" [collapse]="isCollapsed">       <ul class="nav navbar-nav">         <li class="active"><a href="#">Link</a></li>         <li><a href="#">Link</a></li>       </ul>     </div>   </div> </nav> 
like image 66
IlyaSurmay Avatar answered Sep 21 '22 10:09

IlyaSurmay


In Angular V7 with the following config

    Angular CLI: 7.2.2
    Node: 10.14.1
    OS: win32 x64
    Angular: 7.2.1

Thanks @llyaSurmay Really a good example. My case was slightly different without collapsible module also using feature module just like below

enter image description here

If you are using feature module then you need to add your dropdownmodule imports there as well enter image description here

Hope it helps someone who is trying to implement the ngx-bootstrap dropdown module in to the navbar. Thanks

like image 37
Ragavan Rajan Avatar answered Sep 24 '22 10:09

Ragavan Rajan