Utilizing Bootstrap 4 with Angular 2 CLI

Currently, I am delving into the world of Angular2 CLI on my local server at http://localhost:4200/. Following the tutorial from , I have successfully installed Angular2.

However, I encountered an issue while trying to import Bootstrap4 CSS. I attempted to add the following code snippet to my src/angular.json file:

"assets": [
  "src/favicon.ico",
  "src/assets"
],
"styles": [
  "src/styles.css",
  "src/assets/css/bootstrap.min.css",
  "src/assets/css/style.css"
],
"scripts": [
  "src/assets/js/jquery.min.js",
  "src/assets/js/bootstrap.min.js"
],

In addition, I inserted a bootstrap sample navbar into my app.component.html:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>      
    </ul>
  </div>
</nav>

I seem to be encountering the [WDS] Disconnected! error locally.

https://i.sstatic.net/DBC5u.png

To resolve this, I tried adding

import 'src/assets/css/bootstrap.css';
in my style.css, but it ended up as an inline style and did not produce the desired outcome.

While including the index.html header using <link src="" does work, I would prefer an alternative method. Any assistance on this matter would be greatly appreciated. Thank you in advance.

Answer №1

Here is a helpful command for you to try out:

npm install bootstrap@4 jquery --save 

Next, make sure to update the Angular.json file by changing the `"style"` to include:

["node_modules/bootstrap/dist/css/bootstrap.css"]`

Also, add the following scripts to your Angular.json file:

"scripts":["/node_modules/jquery/dist/jquery.js"]`and ["node_modules/bootstrap/dist/js/bootstrap.js"`

Answer №2

Although it may not provide a definitive solution to your query, I suggest using ng-bootstrap instead of Bootstrap in your Angular project for better compatibility without the need for installing jQuery. You can find more information about ng-bootstrap.

To integrate ng-bootstrap into your project:

  1. Execute the command: npm i @ng-bootstrap/ng-bootstrap
  2. Import necessary modules like NgbAlertModule from '@ng-bootstrap/ng-bootstrap' to utilize Bootstrap components such as modals and alerts in your Angular component.

Answer №3

Make sure you

npm install bootstrap

then, include it from the node modules folder in your style.css file

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Text loaded dynamically is not remaining within the div

I am experiencing an issue with dynamically loaded content where Images work fine, but Links and Text are not displaying properly. For reference, you can view the problem in this JSFiddle: http://jsfiddle.net/HRs3u/1/ I suspect that it might be related t ...

Issue with linking CSS file to EJS file in Express.js

After carefully reviewing the setup of my folders and code structure, I am confident that I have correctly linked the CSS to the EJS file. Despite this, I am still facing issues as it is not working properly. To provide a visual reference, I have include ...

Using mousedown, mousemove, and mouseup to handle touch events in vanilla JavaScript instead of jQuery

Can someone guide me on how to set up a touch event handler in JavaScript using the mousedown, mousemove, and mouseup events? I would really appreciate any suggestions or tips! ...

Unable to get table borders to display correctly using CSS styling

Can someone lend me a hand with a CSS issue I'm facing? I want to create some CSS "classes" for tables in my form, but I can only get the borders to display correctly on one of the tables. Here is the code I've been using: table.paddedTable tabl ...

Encountering a Type Error in React Native when attempting to create a 3D cube with Three.js

Following a tutorial on creating a simple app that displays a 3D cube, I encountered an issue with my code: import React from 'react' import {View} from 'react-native' import Expo from 'expo' import {Scene, Mesh, MeshBasicMate ...

I would like the dropdown menu to only appear on mobile devices

After creating a dropdown menu, I now want it to only appear in mobile view and not in other views. I believe this can be achieved using "visible-xs" or a similar method, but I am struggling with the coding. Below is my HTML code: <nav class="navb ...

Verification of email address is not located in Clerk Auth, resulting in a 404 error message

For the past couple of days, I've been stuck on this issue and any help would be greatly appreciated. Thank you in advance! If necessary, I can provide additional code snippets. I am currently working on a project using nextjs with src. I'm try ...

Is there a way to change the color of just the most recently clicked anchor element <a>?

I have a sidebar with anchor elements (Link 1,2,3 in my HTML). I want the text color of these anchors to change when clicked. Additionally, I need only one anchor element to be colored at a time, meaning the previous one should return to its normal color. ...

Using an image tag with dual quotes in Vue.js

I am currently working on a feature where users can upload an image and then have it displayed after the upload is complete. However, I am facing an issue where the response link of the image contains a double quote, and when I use the <img> tag to ...

Unfortunately, I am currently unable to showcase the specifics of the items on my website

I am trying to create a functionality where clicking on a product enlarges the image and shows the details of the product as well. While I have successfully implemented the image enlargement, I am facing challenges in displaying the product details. Below ...

Retrieve the identifier of the parent li element

We have an HTML structure shown below. A jQuery function is triggered when the click me link is clicked. Is it possible to retrieve the id of the enclosing li element from this function? If yes, how can this be achieved? <ul> <li id="20"> &l ...

The compatibility of Cordova CSS properties varies across different devices

I am currently using the ionic framework to develop my upcoming app. I encountered an issue while trying to set a background SVG image for body. The background displayed perfectly on desktop browsers like Firefox and Chrome, as well as on my Nexus 4 device ...

Issue Alert: Inconsistencies with Google Scripts spreadsheets

Objective I have been working on a script that will make consecutive calls to an API (with a JSON response) and input the data into a Spreadsheet. Issue: When I debug the script, everything runs smoothly without any major problems. However, when I try r ...

What is the preferred approach in JavaScript: having a single large file or multiple smaller files?

Having a multitude of JavaScript files loaded on a single page can result in decreased performance. My inquiry is this: Is it preferable to have individual files or combine them into one JavaScript file? If consolidating all scripts into one file is the ...

Simple steps for Mocking an API call (Get Todos) using ComponentDidMount in React with Typescript, Jest, and Enzyme

About the application This application serves as a basic To Do List. It retrieves tasks from an API located at https://jsonplaceholder.typicode.com/todos?&_limit=5. Objective of the project The main goal is to test an API call that triggers ...

Error message: 'html' is not a defined data type in jQuery Ajax

Having some trouble with my jQuery ajax code while working on it in Firebug. I keep getting a ReferenceError: jQuery(document).ready(function() { jQuery('.my-div').click(function(e){ e.preventDefault(); var href = jQuery(this).attr(& ...

problems encountered when including next.config.js for sitemap creation in a nextjs application

Just recently, I made an update to my next.config.json file in hopes of boosting SEO performance. However, this change has caused some issues with the next-sitemap module, preventing me from building or starting my app. //next.config.js const withSitemap = ...

Performing calculations on PHP and MySQL data within an HTML table, enabling precise percentage

Here's the code I'm currently working with: <td> <?php echo $row['feild1'] + $row['feild2'] + $row['feild3'] + $row['feild4'] + $row['feild5'] + $row['feild6'] + $row[' ...

When utilizing the getIntersectionList function, IE 9 may experience a malfunction and cease functioning

I am currently working with SVG code and JavaScript, trying to achieve a specific intersection result. <svg id="svgSurface" width="500" height="500"> <defs> <marker id="Triangle" viewBox="0 0 20 20" refX="0" refY="0" markerUnits ...

Verify whether a loss of focus event was triggered by a tab switch

Is there a way to detect when an input loses focus due to a tab switch or window losing focus? Scenario: I need to reset a form on blur, but I want the data to persist if a user switches tabs or the window loses focus. I know I could simply check for a c ...