ngx-Bootstrap 4下拉菜单和导航栏不适用于Angular 7

时间:2019-04-05 16:04:35

标签: angular bootstrap-4 dropdown angular7 ngx-bootstrap

我正在尝试将Bootstrap 4添加到Angular 7中,我看到样式被Bootstrap样式覆盖,但是导航栏和下拉框不起作用。

我跟随this document将Bootstrap添加到Angular 7项目。 我已将以下代码添加到angular.json

 "styles": [
          "src/styles.css",
          "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.js",
           "node_modules/popper.js/dist/umd/popper.js",
          "node_modules/bootstrap/dist/js/bootstrap.bundle.js"
        ]

这里是code,关于我无法进行堆叠闪电射击的情况

这是简单的jQuery Bootstrap example,可以正常工作

1 个答案:

答案 0 :(得分:1)

需要对your code进行一些更改才能使其工作...添加了dropdowndropdownToggle*dropdownMenu

检查已更新/正常运行的 app.component.html

<div class="container">
<hello name="{{ name }}"></hello>
<p>
  Start editing to see some magic happen :)
</p>

<button type="button" class="btn btn-primary">Primary</button>

<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
  <!-- Brand -->
  <a class="navbar-brand" href="#">Logo</a>

  <!-- Links -->
  <ul class="navbar-nav">
    <li class="nav-item">
      <a class="nav-link" href="#">Link 1</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Link 2</a>
    </li>

    <!-- Dropdown -->
    <li class="nav-item dropdown" dropdown>
      <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown" dropdownToggle>
        Dropdown link
      </a>
      <div class="dropdown-menu" *dropdownMenu>
        <a class="dropdown-item" href="#">Link 1</a>
        <a class="dropdown-item" href="#">Link 2</a>
        <a class="dropdown-item" href="#">Link 3</a>
      </div>
    </li>
  </ul>
</nav>

<div class="dropdown" dropdown>
  <button class="btn btn-primary dropdown-toggle" type="button" dropdownToggle >Dropdown Example
  <span class="caret"></span></button>
  <ul class="dropdown-menu" *dropdownMenu>
    <li><a href="#">HTML</a></li>
    <li><a href="#">CSS</a></li>
    <li><a href="#">JavaScript</a></li>
  </ul>
</div>
</div>