Import popular javascript library into Angular 2 project - Tuong-Nguyen/Angular-D3-Cometd GitHub Wiki

JQuery:

npm package:

  • Install JQuery:
npm install --save jquery
  • Import to our file:
import * as $ from 'jquery'

CDN:

  • Import library in index.html:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  • Declare $ variable at top of any file where we want to use it:
declare let $: any

lodash, underscore,...

Same as JQuery

Note that when using a library through CDN, we can not test our code because of Reference error

⚠️ **GitHub.com Fallback** ⚠️