Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngx-bootstrap dropdown not opening angular 4 bootstrap 4

I can't figure out what's going on here - I've included ngx-dropdown code that I believe is correct based on documentation:

home.component.html

    <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>

app.module.ts

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

site.module.ts (this is the module that contains the home component)

@NgModule({
  imports: [
    BsDropdownModule,

I'm using angular-cli and I've included the bootstrap style:

    "../node_modules/bootstrap/dist/css/bootstrap.min.css",

and in index.html I've added a snippet to let the browser know I'm using bootstrap 4:

<script>window.__theme = 'bs4';</script>
<app-root>Loading . . .</app-root>

The button appears, and there are no errors shown in the console. I can see the dom changing when I click the button ("open" and "show" are being added to the styles). But nothing below the button opens up - no menu is shown.

I don't know where else to look

like image 836
jb44 Avatar asked Aug 17 '17 00:08

jb44


2 Answers

I have this problem too. After some wasted hours i found this:

It's an official issue:

https://github.com/valor-software/ngx-bootstrap/issues/2413

like image 54
Matthias Schaffer Avatar answered Oct 01 '22 16:10

Matthias Schaffer


I had the same problem. After I importing `import { BrowserAnimationsModule } from '@angular/platform-browser/animations';' to app.module.ts and add BrowserAnimationsModule to imports: [] the problem is resolved. With some unnecessary codes, you app.module.ts should look like below. I'm currently using Angular 9.0:

import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
...
@NgModule({
 ...
},
 imports:[
  BrowserAnimationsModule,
  BsDropdownModule.forRoot()
 ],
 ....
})
like image 37
Auguste Avatar answered Oct 02 '22 16:10

Auguste