Aakash Thakur
Aakash Thakur

Reputation: 3895

Bootstrap 3 in angular2 not working

I am trying to use bootstrap in angular2. I have installed the boostrap and jquery dependency with npm install --save bootstrap and npm install --save jquery respectively. This is how I reference it in my index.html-

<html>
<head>
<link data-require="[email protected]" data-semver="3.3.7"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

  <script src="node_modules/core-js/client/shim.min.js"></script>
  <script src="node_modules/zone.js/dist/zone.js"></script>
  <script src="node_modules/reflect-metadata/Reflect.js"></script>
  <script src="node_modules/systemjs/dist/system.src.js"></script>

<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>

  <script src="systemjs.config.js"></script>
  <script>
    System.import('applicationStartup').catch(function (err) {
      console.error(err);
    });
  </script>
</head>

<body>
  <my-app><button class="btn btn-primary">Hello from Angular 2</button></my-app>

</body>

</html>

I have applied bootstrap styling in button above but its just displaying plain HTML button. I tried with CDN's as well but couldn't see any difference.

Is there some other config also that I need to do. I checked on different blogs but couldn't find a relevant answer to this problem.

Thanks for any help that comes my way.

Upvotes: 0

Views: 378

Answers (1)

DC-
DC-

Reputation: 101

Add these two cdn in your header then it will work fine:

 <link rel="stylesheet"        href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 <!-- Optional Bootstrap theme -->
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">

or you need to go project folder and run this command from cmd npm install --save bootstrap then go to angular-cli.json folder and search for styles property in the json and include "

styles": [
      "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "styles.css"
      ],

Upvotes: 1

Related Questions