我一直在尝试在Angular项目中将Bootstrap <link>
和<script>
标记添加到我的HTML中。我从here获得了所有CDN,但是我收到以下错误
Uncaught TypeError: Cannot read property 'fn' of undefined
at bootstrap.min.js:6
我做错了什么?这是我的index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
</body>
</html>
更新:我在这个问题中加入了electron
标签,因为这是一个运行Electron框架的Angular项目,现在想它可能是问题的一部分。
答案 0 :(得分:1)
我注意到了
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"
对我来说不应该在那里。这可能是造成这个问题的原因。
同时强>
为什么不在本地添加引导程序呢?它有很多优点,也是我们大多数人都这样做的。
:
(对于Bootstrap 4(测试中)):
npm install bootstrap@next --save
或强>
(对于Bootstrap 3)
npm install bootstrap --save
配置.angular-cli.json
:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.scss"
]
配置src/style.css
或src/style.scss
:
@import '~bootstrap/dist/css/bootstrap.min.css';
或者你可以使用ngx-bootsrap,它是一个用于引导程序的角度包装器。
有这样的起伏。 ngx-bootstrap总体上缺少许多组件,并且没有最新和最好的引导程序,但至少它是为角度使用而定制的。
来源:答案 1 :(得分:0)
可能与此有关: link
尝试仅包含缩小版本(不是slim.min):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
答案 2 :(得分:0)
Bootstrap依赖于jQuery。在索引HTML中,在包含任何Javascript导入之前,您将要执行以下操作:
<script>
var $ = jQuery = require("jquery")
</script>