3

What is the correct way to import bootstrap in Angular 6. In previous versions I did it this way and it worked correctly.

angular-cli.json (Angular 5)

"styles": [
    "styles.scss"
  ],
"scripts": [
    "../node_modules/jquery/dist/jquery.slim.min.js",
    "../node_modules/popper.js/dist/umd/popper.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

angular.json (Angular 6)

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

get error:

Error: ENOENT: no such file or directory, open '/Users/pacozevallos/myApp/node_modules/jquery/dist/jquery.slim.min.js'

2 Answers 2

7

This configuration should work because as you see in angular.json file there is property "root": "", for importing files, so follow below piece of code

"styles": [
   "src/styles.scss",
   "node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
   "node_modules/jquery/dist/jquery.slim.min.js",
   "node_modules/popper.js/dist/umd/popper.min.js",
   "node_modules/bootstrap/dist/js/bootstrap.min.js"
]
Sign up to request clarification or add additional context in comments.

1 Comment

This works for me I'm just seeing some changes of angular 6 thanks for the help
0

I see your error is showing a jquery file missing. But the bootstrap 4 does not need jquery. If you are using the command npm install --save @ng-bootstrap/ng-bootstrap from angular-cli I think is not need for a jquery dependency. Also need to add to the main module and the module that you want to implement the bootstrap styling the import statement:

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';

It is not necessary to install jquery, might interfere with ng-bootstrap code. Maybe you need to remove any jquery that you may installed.

1 Comment

The OP was talking about bootstrap from getbootstrap.com, not ng-bootstrap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.