Home > Web Front-end > JS Tutorial > body text

How to use third-party js library in angular2 (detailed tutorial)

亚连
Release: 2018-06-04 14:08:15
Original
2111 people have browsed it

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
Copy after login

2. Introduce jquery

import * as $ from 'jquery';
Copy after login

3. Use

$('body').addClass('');
Copy after login

Second type: No declaration file, custom js library

1. Introduce js file into index.html

<script src="/assets/jquery.min.js"></script>
Copy after login

Use the definition in the ts file:

declare var $: any;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!