mutantkeyboard
mutantkeyboard

Reputation: 1724

Bootstrap 4 with Angular 4 navbar

I have created an Angular 4 application, and I wan to use Bootstrap 4 with it.

I installed the Bootstrap 4.0.0-beta6 via npm, and wanted to use the starter template which should look like this.

Proper Start template

I have placed everything accordingly to a angular.cli.json which looks like this:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "frontend"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "styles.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/popper.js/dist/esm/popper.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

When I do ng build or ng serve I got no error or whatsoever, and I can load the page.

However navbar is all broken down, and looks like this:

broken nav

When I inspect the page, I see no error, and I can call the classes.

Also I have purposely skipped NgBootstrap, since I wanted to use the native libs first.

And before asking here, I even tried the MaxCDN versions of both CSS and JS, and I've got the same results.

And my code structure looks similar to this.

Index.html contains <app-component> - which loads the <app-body> which contains simply <app-navigation> and the rest of the container. (Nothing fancy).

I don't know if someone has faced the similar problem.

Any help or suggestion would be welcome.

Upvotes: 0

Views: 1915

Answers (1)

Andrez Segovia
Andrez Segovia

Reputation: 146

Your problem is the import path of library popper.js, change its location path to

../node_modules/popper.js/dist/umd/popper.min.js

Upvotes: 1

Related Questions