This question already has an answer here:
- How to use bootstrap 4 in angular 2? 11 answers
app.component.ts I have tried to add styles dependency in angular.json package but showing that the module not found. adding two of the bootstrap files. here is the screenshot of both the files
the angular.json file is like this angular.json file
afterwards, inside
angular.json
(previously.angular-cli.json
) inside the project's root folder, find styles and add the bootstrap css file like this:You are using Angular v6 not 2
CLI projects in angular 6 onwards will be using
angular.json
instead of.angular-cli.json
for build and project configuration.Each CLI workspace has projects, each project has targets, and each target can have configurations.Docs
OPTION-1
execute
npm install bootstrap@4 jquery --save
The JavaScript parts of
Bootstrap
are dependent onjQuery
. So you need thejQuery
JavaScript
library file too.In your angular.json add the file paths to the styles and scripts array in under
build
targetNOTE: Before v6 the Angular CLI project configuration was stored in
<PATH_TO_PROJECT>/.angular-cli.json.
As of v6 the location of the file changed toangular.json.
Since there is no longer a leading dot, the file is no longer hidden by default and is on the same level.which also means that file paths in angular.json should not contain leading dots and slash
In
.angular-cli.json
file Path was"../node_modules/"
In
angular.json
it is"node_modules/"
OPTION 2
Add files from CDN (Content Delivery Network) to your project CDN LINK
Open file src/index.html and insert
the
<link>
element at the end of the head section to include the Bootstrap CSS filea
<script>
element to include jQuery at the bottom of the body sectiona
<script>
element to include Popper.js at the bottom of the body sectiona
<script>
element to include the Bootstrap JavaScript file at the bottom of the body sectionOPTION 3
Execute
npm install bootstrap
In
src/styles.css
add the following line:@import "~bootstrap/dist/css/bootstrap.css";
OPTION-4
ng-bootstrap It contains a set of native Angular directives based on Bootstrap’s markup and CSS. As a result, it's not dependent on jQuery or Bootstrap’s JavaScript
After Installation import it in your root module and register it in
@NgModule
imports` arrayNOTE
ng-bootstrap
requires Bootstrap's 4 css to be added in your project. you need to Install it explicitly via:npm install bootstrap@4 --save
In your angular.json add the file paths to the styles array in underbuild
targetusing command
open .angular.json old (.angular-cli.json ) file find the "styles" add the bootstrap css file
and add relevent files into
angular.json
file under thestyle
property for css files and underscripts
for JS files.