How do I use Bootstrap in an Angular2 app?
In my current project I want to add dropdown lists, for which I took the code from this one. After adding the below code, the dropdown menu appears like in the example, but when I click, nothing happens.
<li class="dropdown">
<a [routerLink]="['/frontendai']" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Application Insights <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a [routerLink]="['/frontendai']">FrontEnd AI</a></li>
<li class="divider"></li>
<li><a [routerLink]="['/apiai']">API AI</a></li>
<li class="divider"></li>
<li><a [routerLink]="['/apiai']">SQL Exception</a></li>
</ul>
</li>
I was using Bootstrap version 3.3.7 and added the following lines to index.cshtml
<link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
How can I use Bootstrap dropdown in Angular 2 project?
+3
source to share
1 answer
ngx-bootstrap is available for Angular project (above version 2).
Here is the link: http://valor-software.com/ngx-bootstrap/#/dropdowns
You can use it in your project.
Instructions
do npm install ngx-bootstrap --save
Import dropdown module
// RECOMMENDED (doesn't work with system.js)
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
// or
import { BsDropdownModule } from 'ngx-bootstrap';
@NgModule({
imports: [BsDropdownModule.forRoot(),...]
})
export class AppModule(){}
<div class="btn-group" dropdown>
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">
Button dropdown <span class="caret"></span>
</button>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
</div>
+5
source to share