Reputation: 23
I am trying to add Bootstrap to my Angular app. I am new to this and although following the required steps I am having problems getting the bootstrap installed.
I did all the necessary steps from installing Angular cli, ng new first-app and ng serve.
I opened the vs code terminal and tried installing bootstrap using
npm install bootstrap --save
Then adding this in the style.css
@import "~bootstrap/dist/css/bootstrap.css"
But still when I click on the link hovering over the above piece of code it says unable to locate file and prompts for creating a file with this path.
Upvotes: 2
Views: 3981
Reputation: 191
If you want to add [email protected] || Here is the procedure.
Step 1. Install bootstrap. Run this command in your terminal.
npm install [email protected]
Step 2. Install Jquery. Run this command
npm install jquery
Step 3. Then, go to the angular.json file
...
"styles": [
"src/styles.css",
"./node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
...
Step 4. Don't forget to restart your app.
Upvotes: 0
Reputation: 1687
Add the below line in the style.css
file which is present under the src
folder inside the project.
@import '~bootstrap/dist/css/bootstrap.min.css';
Upvotes: 2
Reputation: 15
An easy method to add bootstrap is by using Angular CLI(npm install).
From the command line interface install bootstrap and references it in angular.json
npm install bootstrap --save
Upvotes: 0
Reputation: 1918
If you just want to add the styles from bootstrap there is a property in the angular.json file that allows you to include it in the build.
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"projects": {
"yourproject": {
"architect": {
"build": {
"options": {
"styles": [
"src/styles.scss",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
]
},
...
See: https://angular.io/guide/workspace-config#styles-and-scripts-configuration
Upvotes: 3
Reputation: 17118
Welcome to StackOverflow!
Bootstrap isn't TypeScript code, so you don't import it as such. Instead, it is CSS code, and thus you want to import it in your index.html
file as a `
Here's how I import boostrap in my apps -- the below goes into the <head>
tag of index.html
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
Doing this then allows me to use Bootstrap within any of my code templates.
BTW, that code will link to the 4.3.1 version -- if you want to link to a different version, you can go to https://getbootstrap.com/ and get a "fresh" link -- the site is very helpful in getting you going with the CDN links.
But I see that you want to import it into your styles.css file, so you'll likely have to use a relative path, probably something like:
@import "../node_modules/bootstrap/dist/css/bootstrap.css";
Upvotes: 0