简体   繁体   English

angular2中的Bootstrap 3无法正常工作

[英]Bootstrap 3 in angular2 not working

I am trying to use bootstrap in angular2. 我正在尝试在angular2中使用引导程序。 I have installed the boostrap and jquery dependency with npm install --save bootstrap and npm install --save jquery respectively. 我已经分别使用npm install --save bootstrapnpm install --save jquery安装了boostrap和jquery依赖项。 This is how I reference it in my index.html - 这就是我在index.html中引用它的方式-

<html>
<head>
<link data-require="bootstrap-css@3.3.7" 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. 我在上面的按钮中应用了自举样式,但它仅显示纯HTML按钮。 I tried with CDN's as well but couldn't see any difference. 我也尝试过CDN,但看不到任何区别。

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. 感谢您提供的任何帮助。

Add these two cdn in your header then it will work fine: 在您的标头中添加这两个CDN,即可正常运行:

 <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 " 或您需要进入项目文件夹并从cmd npm install --save bootstrap运行此命令,然后转到angular-cli.json文件夹并在json中搜索styles属性,并包括“

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM