html - Bootstrap 和 Angular 未捕获的类型错误

标签 html css angular bootstrap-4 electron

我一直在尝试添加 Bootstrap <link><script>在 Angular 元素中标记到我的 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 元素,现在认为它可能是问题的一部分。

最佳答案

我注意到了

integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"

这对我来说不应该存在。这可能是导致问题的原因。

还有

为什么不在本地添加 Bootstrap 呢?它有很多优点,我们大多数人也是这样做的。

  1. 在您的 Powershell 或 CMD 或您的 IDE(编码程序)的控制台类型中:

    (对于 Bootstrap 4(测试版)):

    npm install bootstrap@next --save

    (对于 Bootstrap 3)

    npm install bootstrap --save

  2. 配置.angular-cli.json:

    “样式”:[ “../node_modules/bootstrap/dist/css/bootstrap.min.css”, “样式.scss” ]

  3. 配置src/style.csssrc/style.scss:

    @import '~bootstrap/dist/css/bootstrap.min.css';

或者您可以使用 ngx-bootsrap,它是 Bootstrap 的 Angular package 器。

这有起有落。 ngx-bootstrap 总体上缺少许多组件,并且在 bootstrap 中没有最新最好的组件,但至少它是为在 angular 中使用而量身定制的。

来源:

关于html - Bootstrap 和 Angular 未捕获的类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50043696/

相关文章:

css - 2 列 CSS float 布局

angular - Angular,Nginx,Docker在页面刷新时导致404错误

angular - 如何在 Angular 中重置更改事件

显示 block 后单击时的 Javascript 转换

CSS 不透明动画 safari 错误?

javascript - 如何将代码添加到 &lt;script&gt; &lt;/script&gt; 中

html - 如何在 Bootstrap 4 SCSS 中设置粗体字体而不是字体粗细?

javascript - Angular 为什么 $event 对象更改属性

javascript - 使用 jquery 从 html 表生成 excel 表

javascript - IE10 的 readAsBinaryString 替代方案