【问题标题】:Using jquery with Angular 4在 Angular 4 中使用 jquery
【发布时间】:2018-07-03 23:19:13
【问题描述】:

我想展示一个引导模式,但我还是得到了

SectionDetailComponent.html:54 ERROR TypeError: $(...).modal is not a function

我的 .angular-cli:

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

我的组件:

declare var jquery:any;
declare var $:any;

【问题讨论】:

  • 你应该尝试使用 ngx-bootstrap 或 ng-bootstrap 而不是使用常规 bootstrap.js 来使用 bootstrap 4 .ng-bootstrap.github.io/#/home 。它专为 Angular 4 设计
  • 感谢您的回答,我真正的问题是 Popper.js,我只需要在 jquery 之后和引导之前添加内部脚本
  • Angular 版本的 Bootstrap(ng-bootstrap 或 ngx-bootstrap)比 Bootstrap + jQuery 与 Angular 一起工作得更好、更自然。注意:我没有在这里投反对票。

标签: jquery angular typescript bootstrap-4


【解决方案1】:

已解决:

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/popper.js/dist/umd/popper.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],

【讨论】:

  • 老实说,甚至不需要将 jquery 与 angular 一起使用。 Angular 的内置库可以做 jquery 所做的一切。
猜你喜欢
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多