Bootstrap 导航栏切换图标按钮在点击时不显示导航项?

Bootstrap Navbar toggle icon button not showing nav items on click?

我在项目中使用 bootstrap 一直非常顺利,但是在一个 angular 项目中,它的导航栏切换器图标按钮出现了,但在单击按钮时没有显示导航项。

<div>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="#">Admin Header</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive"
                aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarResponsive">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item" routerLinkActive="active">
                        <a class="nav-link" routerLink="./home">Home
                            <span class="sr-only">(current)</span>
                        </a>
                    </li>
                    <li class="nav-item" routerLinkActive="active">
                        <a class="nav-link" routerLink="./about">About</a>
                    </li>
                    <li class="nav-item" routerLinkActive="active">
                        <a class="nav-link" routerLink="./services">Services</a>
                    </li>
                    <li class="nav-item" routerLinkActive="active">
                        <a class="nav-link" routerLink="./contact">Contact</a>
                    </li>
                    <li class=" btn-primary nav-item text-white" role="button">
                        <a class="nav-link text-white" (click)="logOut()" >logout</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</div>

这是导航栏结果:

在减小浏览器的宽度时,我们得到如下结果:

下面是index.html的代码:

但是点击这个按钮我看不到任何导航项。

工作得很好,您一定是缺少一些脚本文件。

<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

  <title>Hello, world!</title>
</head>

<body>
  <div>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
      <div class="container">
        <a class="navbar-brand" href="#">Admin Header</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
        <div class="collapse navbar-collapse" id="navbarResponsive">
          <ul class="navbar-nav ml-auto">
            <li class="nav-item" routerLinkActive="active">
              <a class="nav-link" routerLink="./home">Home
                            <span class="sr-only">(current)</span>
                        </a>
            </li>
            <li class="nav-item" routerLinkActive="active">
              <a class="nav-link" routerLink="./about">About</a>
            </li>
            <li class="nav-item" routerLinkActive="active">
              <a class="nav-link" routerLink="./services">Services</a>
            </li>
            <li class="nav-item" routerLinkActive="active">
              <a class="nav-link" routerLink="./contact">Contact</a>
            </li>
            <li class=" btn-primary nav-item text-white" role="button">
              <a class="nav-link text-white" (click)="logOut()">logout</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>
  </div>

  <!-- JavaScript -->
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>

</html>