Home > Article > Web Front-end > How to use third-party js library in angular2 (detailed tutorial)
Below I will share with you an example of using a third-party js library in angular2. It has a good reference value and I hope it will be helpful to everyone.
This article takes jquery as an example
The first type: There is a corresponding declaration file
1. Install the jQuery declaration file with the command. (The declaration file is for the perfect intelligent prompt of ide)
npm install -D @types/jquery
2. Introduce jquery
import * as $ from 'jquery';
3. Use
$('body').addClass('');
Second type: No declaration file, custom js library
1. Introduce js file into index.html
<script src="/assets/jquery.min.js"></script>
Use the definition in the ts file:
declare var $: any;
Then it can be used normally.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use superagent and cheerio using nodejs crawler
Method by introducing noVNC remote desktop into the vue project What are the steps
By using ueditor in vue project (detailed tutorial)
The above is the detailed content of How to use third-party js library in angular2 (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!