[英]Add jquery to angular 2 wepack project (Bootstrap's JavaScript requires jQuery)
I'm using the angular-cli .net core starter.我正在使用 angular-cli .net 核心启动器。 Now I'm adding my own css + javascript and getting following error:
现在我正在添加我自己的 css + javascript 并收到以下错误:
An unhandled exception occurred while processing the request.
处理请求时发生未处理的异常。 Exception: Call to Node module failed with error: Prerendering failed because of error: Error: Bootstrap's JavaScript requires jQuery
异常:调用节点模块失败,错误:预渲染失败,因为错误:错误:Bootstrap 的 JavaScript 需要 jQuery
I already tried:我已经尝试过:
npm install jquery
+ +
import $ from 'jquery'; => in app component
How do you configure jquery with webpack / angular2 ?你如何使用 webpack/angular2 配置 jquery?
Thanks!谢谢!
安装类型定义:
npm install @types/jquery
steps脚步
npm install jquery — save
Add "scripts": [ "../node_modules/jquery/dist/jquery.min.js" ]
to angular-cli.json file添加
"scripts": [ "../node_modules/jquery/dist/jquery.min.js" ]
到 angular-cli.json 文件
Import it into the component : import * as $ from 'jquery';
将其导入到组件中:
import * as $ from 'jquery';
Example:例子:
$(document).ready(function(){ $("button").click(function(){ ... } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.