我正在尝试在Angular2中使用bootstrap。我分别使用npm install --save bootstrap
和npm install --save jquery
安装了Boostrap和jQuery依赖性。这就是我在 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>
我已经在上面的按钮中应用了引导样式,但它只是显示了普通的HTML按钮。我也尝试了CDN,但看不到任何区别。
我还需要做其他配置。我检查了不同的博客,但找不到有关此问题的相关答案。
感谢您提供的任何帮助。
在标题中添加这两个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">
或您需要转到项目文件夹并从CMD运行此命令 npm安装 - 节奏bootstrap然后转到Angular-cli.json文件夹并在JSON中搜索样式属性,并包括 "
styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],