Bootstrap 4.2.1汉堡包不可点击

时间:2018-12-24 07:13:32

标签: angular bootstrap-4

我正在使用引导程序4.2.1,并且当窗口缩小时,导航栏会折叠,但是单击时,汉堡包按钮不会显示菜单。我很难为此道歉。当我单击“汉堡包”按钮时,为什么没有显示下拉菜单?我觉得这可能是一个本地问题,我复制了其他人的小偷和引导程序示例,但它不起作用。

<header id="header">
  <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark" role="navigation" >
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
    <div id="navbarSupportedContent" class="collapse navbar-collapse">
      <div class="navbar-nav">
          <a class=" nav-item nav-link" routerLinkActive="active" routerLink="/home"><span class="sr-only">(current)</span>{{home}}</a>
          <a class="nav-item nav-link" routerLinkActive="active" routerLink="/resume">{{resume}}</a>
      </div>
    </div>
  </nav>
</header>
<body class="main-container container-fluid">
    <div id="view">
        <router-outlet></router-outlet>
    </div>
</body>
<footer id="footer">
    <div class="container-fluid navbar-expand-md navbar-dark bg-dark">
        <span class="text-muted d-flex justify-content-center">{{copyright}}</span>
    </div>
</footer>

package.json

  {
  "name": "k",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.1.4",
    "@angular/common": "~7.1.4",
    "@angular/compiler": "~7.1.4",
    "@angular/core": "~7.1.4",
    "@angular/forms": "~7.1.4",
    "@angular/http": "~7.1.4",
    "@angular/platform-browser": "~7.1.4",
    "@angular/platform-browser-dynamic": "~7.1.4",
    "@angular/router": "~7.1.4",
    "bootstrap": "^4.2.1",
    "core-js": "^2.5.4",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.6",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.11.4",
    "@angular/cli": "~7.1.4",
    "@angular/compiler-cli": "~7.1.4",
    "@angular/language-service": "~7.1.4",
    "@types/jasmine": "~3.3.5",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~10.12.18",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.4",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.12.0",
    "typescript": "^3.1.6"
  }
}

1 个答案:

答案 0 :(得分:1)

汉堡包使用bootstrap.js显示移动菜单。因此,请确保您拥有

"scripts": [
   "node_modules/bootstrap/dist/js/bootstrap.min.js"
],

在您的angular.json文件中。

OR

您也可以使用CDN。关键是要使Hamburger菜单正常运行,必须具有bootstrap.js或bootstrap.min.js。