4
votes

I know this question has been asked for many different angular/ngx-bootstrap configurations but as I could not find any helpful answer yet, I decided to open this question.

I am trying to integrate a bootstrap dropdown component using ngx-boostrap:

package.json

"ngx-bootstrap": "^2.0.2",

In the head of my index.html

link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"

In my app.module.ts

import { BsDropdownModule } from 'ngx-bootstrap';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...,
    BsDropdownModule.forRoot()
  ],
  providers: [...],
  bootstrap: [AppComponent]
})

Then I have a submodule where I try to load the dropdown :

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

The dropdown button shows up, but nothing happens when I click it. I checked the DOM using the inspector and the content of the dropdown is still empty.

What can I do to make this dropdown work ?

EDIT

I have no idea how, but after playing around with the imports it ended up working.

I moved back the import of BsDropdownModule in my submodule (which was not working in the begining) and it worked. I guess I made a silly mistake by the time I opened this question but I can't find what. I leave this open in case it may help someone...

2
Can you please update with your dropdownComponent.ts & parent component's template file code?Piyush Rathi
@PiyushRathi I am no longer working on this project sorry :/Louis

2 Answers

0
votes

Hope you are properly using selector: 'demo-dropdown-basic' inn your component.ts and including into parent component's html like <demo-dropdown-basic></demo-dropdown-basic>

-1
votes

Did you tell your button to actually show the dropdown? You need an [isOpen]="whatever", and then maybe another button, service, link, whatever where you toggle that whatever variable, like in the example here.