简体   繁体   English

ngx-bootstrap下拉列表未在Angular 5项目中打开

[英]ngx-bootstrap dropdown not opening in Angular 5 project

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. 我知道这个问题已被要求用于许多不同的角度/ ngx-bootstrap配置,但由于我找不到任何有用的答案,我决定打开这个问题。

I am trying to integrate a bootstrap dropdown component using ngx-boostrap: 我正在尝试使用ngx-boostrap集成一个bootstrap下拉组件:

package.json 的package.json

 "ngx-bootstrap": "^2.0.2", 

In the head of my index.html 在我的index.html的头部

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

In my app.module.ts 在我的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 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. 我使用检查器检查了DOM,下拉列表的内容仍为空。

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. 我在我的子模块中移回了BsDropdownModule的导入(它在开始时没有工作)并且它有效。 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... 我保持开放,以防有人帮助...

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 . 你需要一个[isOpen] =“whatever”,然后可能是另一个按钮,服务,链接,无论你在哪里切换whatever变量,就像这里的例子一样。

希望你正确使用selector: 'demo-dropdown-basic'将你的component.ts包含在父组件的html中,如<demo-dropdown-basic></demo-dropdown-basic>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM