简体   繁体   中英

Add jquery to angular 2 wepack project (Bootstrap's JavaScript requires jQuery)

I'm using the angular-cli .net core starter. Now I'm adding my own css + javascript and getting following error:

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

I already tried:

npm install jquery 

+

import $ from 'jquery'; => in app component

How do you configure jquery with webpack / angular2 ?

Thanks!

安装类型定义:

npm install @types/jquery

steps

  1. npm install jquery — save

  2. Add "scripts": [ "../node_modules/jquery/dist/jquery.min.js" ] to angular-cli.json file

  3. Import it into the component : import * as $ from 'jquery';

  4. Example:

     $(document).ready(function(){ $("button").click(function(){ ... } });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM