ng-bootstrap ngbDropdown不工作Angular 4

时间:2017-07-17 14:08:33

标签: angular bootstrap-4 ng-bootstrap

ng下拉列表不起作用。

注意:我按照here的答案并将bootstrap升级为4-alpha,但它无效。

以下是我的package.json文件:

    "@angular/animations": "^4.3.0",
    "@angular/common": "^4.3.0",
    "@angular/compiler": "^4.3.0",
    "@angular/core": "^4.3.0",
    "@angular/forms": "^4.3.0",
    "@angular/http": "^4.3.0",
    "@angular/platform-browser": "^4.3.0",
    "@angular/platform-browser-dynamic": "^4.3.0",
    "@angular/router": "^4.3.0",
    "@angular/upgrade": "^4.3.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.28",
    "@types/jquery": "^3.2.8",
    "angular-calendar": "^0.19.0",
    "angular2-ladda": "^1.2.1",
    "angular2-text-mask": "^8.0.2",
    "angular2-toaster": "^4.0.1",
    "animate.css": "^3.5.2",
    "bootstrap": "4.0.0-alpha.6"

html代码:

<div ngbDropdown class="d-inline-block">
                <button class="btn btn-outline-primary nav-link dropdown-toggle" id="dropdownBasic1" ngbDropdownToggle>More Actions..</button>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownBasic1">
                    <button class="dropdown-item">Action - 1</button>
                    <button class="dropdown-item">Another Action</button>
                    <button class="dropdown-item">Something else is here</button>
                </div>
            </div>

在我的app.module.ts中也导入了ngbModule。

import {NgbModule} from "@ng-bootstrap/ng-bootstrap";

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    NgbModule.forRoot()
//more
]

Bootstrap按钮和文本输入正常工作,并且所有样式都已应用,但下拉列表不会点击。

enter image description here

非常感谢任何输入。

3 个答案:

答案 0 :(得分:16)

NgbModule也必须在单独的模块中导入。致谢:HaveSpacesuit

答案 1 :(得分:1)

添加您使用的ngb模块, NgbModule必须导入。...

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

答案 2 :(得分:0)

@Maddy 只需对您的HTML代码进行一些小改动:

<div ngbDropdown class="d-inline-block">
                <button class="btn btn-outline-primary nav-link dropdown-toggle" id="dropdownBasic1" ngbDropdownToggle>More Actions..</button>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownBasic1" ngbDropdownMenu >
                    <button class="dropdown-item">Action - 1</button>
                    <button class="dropdown-item">Another Action</button>
                    <button class="dropdown-item">Something else is here</button>
                </div>
            </div>
  

ngbDropdownMenu 是添加到&#34;下拉菜单&#34;格。