1

I'm using the Bootstrap navbar dropdown list to display the menu of products. First time using Bootstrap with Angular 10 and it doesn't work. I installed jquery and bootstrap and added them to angular.json. The buttons produits and username don't work.

enter image description here

Here is my app.component.html code:

<!DOCTYPE html>
<html>

<head>
  <title>Gestion des Produits</title>
  <meta charset="utf-8">
</head>

<body>
  <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
    <!-- Brand -->
    <a class="navbar-brand" href="#">Gestion Produits</a>
    <!-- Links -->
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="#">Home</a>
      </li>
      <!-- Dropdown -->
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
          Produits
        </a>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#">Ajouter</a>
          <a class="dropdown-item" href="#">Lister</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav ml-auto">
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
          [username]
        </a>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#">login</a>
          <a class="dropdown-item" href="#">logout</a>
          <a class="dropdown-item" href="#">Profile</a>
        </div>
      </li>
    </ul>
  </nav>
</body>
</html>
<router-outlet></router-outlet>

and angular.json code:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": "89f1b774-ef8d-48ad-880f-3a83861f3da9"
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "GP": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/GP",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "GP:build:production"
            },
            "development": {
              "browserTarget": "GP:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "GP:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        }
      }
    }
  },
  "defaultProject": "GP"
}

Yong Shun
  • 35,286
  • 4
  • 24
  • 46
  • 1
    Does this answer your question? [Bootstrap not working properly in Angular 6](https://stackoverflow.com/questions/52676474/bootstrap-not-working-properly-in-angular-6) – Yong Shun Aug 06 '21 at 05:41
  • As YongShun's link says, adding popper.js and putting it in the scripts array is likely necessary. – cfitzer Aug 06 '21 at 13:53

0 Answers0